【发布时间】: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>
【问题讨论】:
-
对我来说很好:jsfiddle.net/fS96A
-
@phill-pafford 我试过你的链接,当点击“选择”按钮时它不起作用我留下了 JQM 1.0 jsfiddle.net/5rQUB 和 JQM 1.1 RC jsfiddle.net/JbPS2 的两个版本
-
看起来你可能有错误,也许会引发问题? github.com/jquery/jquery-mobile/issues
-
感谢@phill-pafford 他们修复了,我用最新版本进行了测试并且正在工作
标签: jquery-mobile radio-button