찾다

 >  Q&A  >  본문

javascript - weui 的单选怎么获取文本?

<!--选择性别-->
                                <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“,却拿不到值
大家讲道理大家讲道理2817일 전1134

모든 응답(4)나는 대답할 것이다

  • 大家讲道理

    大家讲道理2017-04-11 11:13:43

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

    회신하다
    0
  • PHP中文网

    PHP中文网2017-04-11 11:13:43

    你都没有给你的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">

    회신하다
    0
  • 大家讲道理

    大家讲道理2017-04-11 11:13:43

    $("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='女'>   

    회신하다
    0
  • 大家讲道理

    大家讲道理2017-04-11 11:13:43

    weui有对应的js,github上有demo

    회신하다
    0
  • 취소회신하다