在我的 ASP.NET MVC4 中,我有两个单选按钮 rb1 和返回以及两个文本框和 txt2...
如何在选中 rb2 时禁用文本框 txt2?
这是我的代码:
下面的代码可能在 HTML 帮助程序或 HTML 标签中
<input type="radio" id="rb1" value="r1" name="jrn" />
<input type="radio" id="rb2" value="r2" name="jrn" checked="checked"/>
<input type="text" name="txt1" id="Ret" value="v1" />
<input type="text" name="txt2" id="Dep" value="v2" />
试试这个
$(function(){
$('#rb2').change(function() {
if($(this).is(':checked')){
$("#txt2").prop("disabled", true);
}
else
{
$("#txt2").removeAttr("disabled");
}
})
});
如何在
MVC中使用Web表单控件!!!!!
大问题,你不被允许这样做。
更新代码后,您可以使用Javascript来执行所需的操作这是代码
function disablefield()
{
if ( document.admin.customerInfo_0.checked = true)
document.admin.txtPhoneNumber.value = enabled
elseif (admin.customerInfo_1.value="yes")
document.admin.txtLastName.value.enabled=false
}
$(document).ready(function(){
$('#rb2').change(function() {
if($(this).is(':checked')){
$("#txt2").attr("disabled", "disabled");
}
else
{
$("#txt2").removeAttr("disabled");
}
});