我有以下功能,但当单选按钮被选为否时它不会模糊。有什么想法吗?
表格元素:
<td>
Email: Yes? <input type="radio" name="emailquest" value="true" checked>
No? <input type="radio" name="emailquest" value="false">
</td>
<td>
<input type="text" name="email">
</td>
脚本:
<script>
$(document).ready(function(){
$("#emailquest").blur(function(){
if ($(this).val() != true)
$("#email").attr("disabled","disabled");
else
$("#email").removeAttr("disabled");
});
});
</script>
答案 0 :(得分:6)
正如Pointy所说,#
用于ID,而不是名称
$("input[name='emailquest']").change(function(){
if (this.value != "true") { // <----I would probably change this to look for this.checked
$("input[name='email']").prop("disabled", true);
} else {
$("input[name='email']").prop("disabled", false);
}
});
现场演示:http://jsfiddle.net/E3zDB/
使用三元运算符的缩短版本:
$("input[name='emailquest']").change(function(){
var input = $("input[name='email']");
this.value != "true" ? input.prop("disabled", true) : input.prop("disabled", false);
});