javascript - weui 的单选怎么获取文本?
大家讲道理
大家讲道理 2017-04-11 11:11:43
0
4
1109
<!--选择性别-->
                                <p class="weui_cells weui_cells_radio">
                                    <label class="weui_cell weui_check_label" for="x11">
                                        <p id="man" class="weui_cell_bd weui_cell_primary">
                                            <p>男</p>
                                        </p>
                                        <p class="weui_cell_ft">
                                            <input type="radio" class="weui_check" name="radio1" id="x11">
                                            <span class="weui_icon_checked"></span>
                                        </p>
                                    </label>
                                    <label class="weui_cell weui_check_label" for="x12">
                                        <p id="woman" class="weui_cell_bd weui_cell_primary">
                                            <p>女</p>
                                        </p>
                                        <p class="weui_cell_ft">
                                            <input type="radio" name="radio1" class="weui_check" id="x12" checked="checked">
                                            <span class="weui_icon_checked"></span>
                                        </p>
                                    </label>
                                </p>

我要获取”男“或”女“,可是怎么都获取不到,怎么获取?

var doctorSex = $("input[name='radio1']:checked").val();  只能获取个开关”on“,却拿不到值
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
大家讲道理

貌似本来就没有赋值,当然获取不到,判断一下是否checked不是一样嘛

洪涛

你都没有给你的input赋值啊~加个value就行了

<input type="radio" class="weui_check" name="radio1" id="x11" value="male">
<input type="radio" name="radio1" class="weui_check" id="x12" value="female" checked="checked">
大家讲道理

$("input[name='radio1']:checked").val(); 这个选择器是选择name='radio1'并且被选中的input输入框的值,而你所需要的男,女,是一个P标签里边的text。选择器错误。

    <input type="radio" name="radio1" class="weui_check" id="x12" checked="checked" value='男'>
    <input type="radio" class="weui_check" name="radio1" id="x11" value='女'>   
大家讲道理

weui有对应的js,github上有demo

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template