我有一个包含两个单选按钮的表单,我希望在单选按钮被选中时启用相应的域。我的代码只是不工作,那就是:单选按钮启用表单域
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var $type = $('select'),
$field1 = $("#fieldID1"),
$field2 = $("#fieldID2");
$type.change(function() {
var isDisabled = ($type.filter(":checked").val() === "1");
$field1.prop("disabled", !isDisabled);
$field2.prop("disabled", isDisabled);
}).change();
});
</script>
</head>
我的HTML身体就像:
<body>
<form action="" method="post">
<input type="radio" name="select" value="1" />
<input type="text" name="fieldID1" id="fieldID1"/>
<input type="radio" name="select" value="2" />
<table id="fieldID2">
<tr>...</tr>
<tr>...</tr>
...
</table>
<input type="submit" value="Add">
</form>
</body>
我从this post引用的代码。任何人都可以指出我的问题是什么,我对jQuery不太了解,谢谢!
仍无法修复......
你必须通过名称来选择:'输入[名称= “选择”]'。 –
它与刚才使用$('select')相同,我试过了。 – Michael