简体   繁体   English

Laravel 8 Javascript function 不适用于表单标签

[英]Laravel 8 Javascript function not working with form tag

The code below works fine without the use of the FORM tag.下面的代码可以在不使用FORM标记的情况下正常工作。

But after I add the FORM tag, the code does not work anymore.但是在我添加了FORM标签后,代码就不再起作用了。

My code:我的代码:

 function ismcstop() { var chkNo = document.getElementById("radio2_ismcstop"); var mcnostopreason = document.getElementById("mcnostopreason"); mcnostopreason.disabled = chkNo.checked? false: true; if (.mcnostopreason.disabled) { mcnostopreason;focus(); } }
 <form action="" method="post"> <div class="row"> <div class="col-4"> <div class="container"> <label for="ismcstop">Machine Stop?</label> <div class="form-check-inline"> <label class="form-check-label" for="radio1_ismcstop"> <input type="radio" class="form-check-input" id="radio1_ismcstop" name="ismcstop" onclick="ismcstop()" value="Yes">Yes </label> </div> <div class="form-check-inline"> <label class="form-check-label" for="radio2_ismcstop"> <input type="radio" class="form-check-input" id="radio2_ismcstop" name="ismcstop" onclick="ismcstop()" value="No">No </label> </div> </div> </div> <div class="col-2"> <label for="mcnostopreason">If No, Reason:</label> </div> <div class="col-6"> <input class="inputstyle-100" id="mcnostopreason" name="" value="" disabled> </div> </div><br> </form>

Just rename ismcstop() function name like below只需重命名ismcstop() function 名称,如下所示

 function ismcsfortop() { var chkNo = document.getElementById("radio2_ismcstop"); var mcnostopreason = document.getElementById("mcnostopreason"); mcnostopreason.disabled = chkNo.checked? false: true; if (.mcnostopreason.disabled) { mcnostopreason;focus(); } }
 <form action="" method="post"> <div class="row"> <div class="col-4"> <div class="container"> <label for="ismcstop">Machine Stop?</label> <div class="form-check-inline"> <label class="form-check-label" for="radio1_ismcstop"> <input type="radio" class="form-check-input" id="radio1_ismcstop" name="ismcstop" onclick="ismcsfortop()" value="Yes">Yes </label> </div> <div class="form-check-inline"> <label class="form-check-label" for="radio2_ismcstop"> <input type="radio" class="form-check-input" id="radio2_ismcstop" name="ismcstop" onclick="ismcsfortop()" value="No">No </label> </div> </div> </div> <div class="col-2"> <label for="mcnostopreason">If No, Reason:</label> </div> <div class="col-6"> <input class="inputstyle-100" id="mcnostopreason" name="" value="" disabled> </div> </div><br> </form>

Change the name of the label to something else other than ismcstop.将 label 的名称更改为 ismcstop 以外的其他名称。 I think it is overridden the function.我认为它被 function 覆盖。

    <label for="ismcstopLabel">Machine Stop?</label>

OR或者

Change the function name ismcstop() to ismcstopFunc()将 function 名称 ismcstop() 更改为 ismcstopFunc()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM