0
<label for="dessert">What is your favourite dessert?*</label>
<input type="text" id="dessert" onchange="checkForm()"><br>
<div id="dessertmsg">  </div>

<input type="submit" value="Submit" id="subbutton" disabled> 

我想显示按钮。要显示按钮,我希望我的验证为真,即:

  function checkForm()

  {
  var dessert = document.getElementById("dessert").value;

  if(dessert == "cake"|| dessert == "cookie" || dessert == "icecream"){

当它为真时,我希望启用该按钮。我知道我必须使用 disabled: False 但我将如何为此编写代码行?document.getElementById(残疾人的身份证是什么)??

4

3 回答 3

4
function checkForm() { 
    var button = document.getElementById("subbutton");
    var dessert = document.getElementById("dessert").value;
    if(dessert == "cake"|| dessert == "cookie" || dessert == "icecream") {
        button.disabled = undefined;
    }
    else {
        button.disabled = true;
    }
}

示例: http: //jsfiddle.net/3NudE/(有 3 个裸体,哇!)

于 2012-05-13T23:36:04.580 回答
0
if(dessert == "cake"|| dessert == "cookie" || dessert == "icecream"){
    {document.getElementById("subbutton").disabled = false;}

http://www.webdeveloper.com/forum/showthread.php?t=147187

于 2012-05-13T23:39:30.937 回答
0
function checkForm()
{
   var dessert = document.getElementById("dessert").value;
   document.getElementById("subbutton").disabled = (dessert == "cake"|| dessert == "cookie" || dessert == "icecream");
}
于 2012-05-13T23:42:15.357 回答