2017-01-02 59 views
-1

后,我有这个复选框:使能输入选中复选框

<div class="form-group"> 
<input type="checkbox" id="examination" class="form-control" name="exam" placeholder="Enter Title"> 
<label>Enable Exam</label> 
</div> 

这是我的禁用输入:

<div class="form-group"> 
<label>Order</label> 
<input id="myorder" name="myorder" disabled> 
</div> 

我此脚本试图使后选中复选框启用输入,但它不起作用:

$('#examination').change(function(){ 
    $("#myorder").prop("disabled", !$(this).is(':checked')); 
}); 

任何想法?

+0

你肯定有很多的给定答案的问题;没有被接受。 –

+0

此外,你的代码完美的作品。有什么问题 ?也许你忘了包含jquery插件。 –

+0

@ Alexandru-IonutMihai点击复选框后没有任何事发生 –

回答

0

这里,我想这会工作:

<!DOCTYPE html> 
<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script> 
$(document).ready(function(){ 
    $('#chtest').change(function(e){ 
     var isChecked = $(e.target).is(':checked'); 
     if (isChecked) { 
      $("#test").removeAttr("disabled"); 
     } else { 
      $("#test").attr("disabled","disabled"); 
     } 
    }); 
}); 
</script> 
</head> 
<body> 

<form action=""> 
    <input type="text" id="test" disabled="disabled"><br> 
    <input type="checkbox" id="chtest"> 
</form> 


</body> 
</html>