<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>


我想显示按钮。为了显示该按钮,我希望验证为true:

  function checkForm()

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

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


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

最佳答案

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个裸体,呜!)

关于javascript - Javascript功能编号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10576051/

10-09 14:07