Hello, need help pleaseI already tried adding a break on both end of condition ..I Have 5 Textboxes, 1 Button and a Javascript for their function. What i want to do is this..
情况1:当Stat变量的值为“N”时,程序必须要求输入Area、Capital和Code,ADD按钮才能启用,否则它将禁用。
情况 2 当 Stat 变量的值为“R”时,程序必须要求在“面积”、“总面积”和“代码”文本框中输入 ADD 按钮才能启用,否则它将禁用。我尝试过以这种方式编写代码..但它不起作用。
function SetButtonStatus() {
var Stat = document.getElementById('<%=_oTextBoxNRC.ClientID%>').value;
var Area = document.getElementById('<%=_oTextBoxArea.ClientID%>').value;
var Capital = document.getElementById('<%=_oTextBoxCapital.ClientID%>').value;
var Code = document.getElementById('<%= _oTextboxBusLineCode.ClientID%>').value;
var Gross = document.getElementById('<%=_oTextBoxGrossRec.ClientID%>').value;
//Change these conditions as your requirement
switch (Stat) {
case 'N':
if (parseFloat(Area) >= 1 && parseFloat(Capital) >= 1 && Code.length >= 1)
document.getElementById('<%=_oButtonAdd.ClientID%>').disabled = false;
else
document.getElementById('<%=_oButtonAdd.ClientID%>').disabled = true;
break;
case 'R':
if (parseFloat(Area) >= 1 && parseFloat(Gross) >= 1 && Code.length >= 1)
document.getElementById('<%=_oButtonAdd.ClientID%>').disabled = false;
else
document.getElementById('<%=_oButtonAdd.ClientID%>').disabled = true;
break;
}
}
最佳答案
像这样使用setAttribute
和removeAttribute
:
if (parseFloat(Area) >= 1 && parseFloat(Capital) >= 1 && Code.length >= 1)
{
document.getElementById('<%=_oButtonAdd.ClientID%>')
.setAttribute("disabled","disabled");
}
else
{
document.getElementById('<%=_oButtonAdd.ClientID%>')
.removeAttribute('disabled');
}
关于javascript - 使用 case 语句启用/禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47666373/