我希望我的所有文本框字段都使用javascript禁用,并且仅在用户填写了必填字段后才启用,然后才是文本框应可编辑的时间
L_KJJ 回答:如何使用javascript锁定字段并在必填字段中插入值后解锁
下面是您所要求的代码段。
$(document).ready(function() {
setInterval(function() {
if ($("#boxOne").val() != '') {
$("#boxTwo").removeAttr('disabled');
}else{
$("#boxTwo").attr('disabled',true);
}
if ($("#boxTwo").val() != '') {
$("#boxThree").removeAttr('disabled');
}else{
$("#boxThree").attr('disabled',true);
}
},500);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Mandatory box1:<input type="text" id="boxOne"/><br><br>
Text box2:<input type="text" id="boxTwo" disabled/><br><br>
Text box3:<input type="text" id="boxThree" disabled/><br><br>
希望这会有所帮助。