Home > Article > Web Front-end > Why is my jQuery Mobile checkbox validation code failing?
You have written code in jQuery Mobile to validate if a checkbox is checked. Despite your efforts, the code fails to execute.
<script type="text/javascript"> function validate(){ if (remember.checked == 1){ alert("checked") ; } else { alert("You didn't check it! Let me check it for you.") } } </script> <input>
The problem arises from incorrect comparison of the checked property. Instead of comparing it to 1, use the boolean property directly:
function validate(){ var remember = document.getElementById('remember'); if (remember.checked){ alert("checked") ; }else{ alert("You didn't check it! Let me check it for you.") } }
The above is the detailed content of Why is my jQuery Mobile checkbox validation code failing?. For more information, please follow other related articles on the PHP Chinese website!