Get checked radio button when migrate to JQM 1.1 RC1 not working

爱⌒轻易说出口 提交于 2020-01-06 04:38:27

问题


To get the value of checked radio button I use something like this

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

This work well until I upgrade the version of jQuery Mobile from 1.0 to 1.1 rc1, then i could not get the value anymore, i just get "undefined"

I dont understand why something basic like this does not work for a change of JQM lib..

I paste and example

<!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>

回答1:


This was a bug and is now fixed:

  • https://github.com/jquery/jquery-mobile/issues/3687#issuecomment-4251371


来源:https://stackoverflow.com/questions/9500742/get-checked-radio-button-when-migrate-to-jqm-1-1-rc1-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!