1
得到檢查單選按鈕的值,我用的是這樣的得到遏制單選按鈕,當遷移到JQM 1.1 RC1不工作
$('input:radio[name=rbutton]:checked').val()
這項工作做得很好,直到我從1.0升級jQuery Mobile的版本到1.1 RC1,然後我無法得到的值了,我只是得到「未定義」
我不明白爲什麼一些基本的東西像這樣不適合JQM 11b的變化工作..
我粘貼和例子
<!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>
正常工作對我來說:http://jsfiddle.net/fS96A/ – 2012-02-29 16:35:27
@菲爾 - pafford我想你的鏈接當點擊「選定」按鈕時,它不起作用我使用JQM 1.0 http://jsfiddle.net/5rQUB/和JQM 1.1 RC保留了兩個版本http://jsfiddle.net/JbPS2/ – 2012-02-29 20:29:02
看起來你可能有一個錯誤,也許會引發一個問題? https://github.com/jquery/jquery-mobile/issues – 2012-02-29 21:03:39