【问题标题】:Get checked radio button when migrate to JQM 1.1 RC1 not working迁移到 JQM 1.1 RC1 时选中单选按钮不起作用
【发布时间】:2012-03-01 22:00:39
【问题描述】:

为了获得选中单选按钮的值,我使用类似这样的东西

$('input:radio[name=rbutton]:checked').val() 

在我将 jQuery Mobile 的版本从 1.0 升级到 1.1 rc1 之前,这很好用,然后我无法再获得该值,我只是得到“未定义”

我不明白为什么像这样的基本内容不适用于 JQM 库的更改..

我粘贴并举例

<!DOCTYPE html> 
<html> 
<head>
    <meta charset="utf-8">
    <title>test radio button</title>    
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.js"></script>    
    <script>
        $(document).delegate("#test", "pageinit", function(event) {

            $("button.select").bind ( "click", function (e) {
                //  Get value of checked radio with JQM 1.0, but get "undefined" with JQM 1.1 RC
                alert( $('input:radio[name=rbutton]:checked').val()  ); 
            });

            $("input[type=radio]").bind ( "change", function (e) {
                alert ($(this).val());  //OK
            });
        });
    </script>
</head> 
<body> 
<div data-role="page" id="test" >
    <div data-role="content">

        <fieldset data-role="controlgroup">
            <input type="radio" name="rbutton" id="rbutton1" value="1" />
            <label for="rbutton1">Option 1</label>
            <input type="radio" name="rbutton" id="rbutton2" value="2" />
            <label for="rbutton2">Option 2</label>
         </fieldset>
        <button class="select">selected</button>

    </div> <!-- /content -->
</div><!-- /page -->
</body>
</html>

【问题讨论】:

标签: jquery-mobile radio-button


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2014-09-25
    • 2017-07-13
    • 2018-06-15
    • 2018-01-17
    • 2011-04-06
    • 2013-06-22
    • 2016-05-18
    • 2017-03-09
    • 1970-01-01
    相关资源
    最近更新 更多