input type = "checkbox" checked by value, does not explain the method selected by value

When using the form form recently, there has been a problem, checkbox checked will pass if true, did not pass on what is selected, but this is not the desired effect, I hope he did pass true when selected, pass false when not selected.

Then there are two ways

1.

<input name="public" type="checkbox" onclick="javascript:document.getElementById('public').value=this.checked;">  
<input name="public" type="hidden" value="false" id="public">  

2.

Generating such forms, when the checkbox is not checked when submitting a hidden form. false is submitted to the server.

When the checkbox is checked all the time, hidden and checkbox forms were submitted, but because their name is the same, so the value of the hidden checkbox is covered. So it was true.

This method is simple and ingenious, worthy of promotion .

<input name="public" type="hidden" value="false">  
<input name="public" type="checkbox" value="true" id="public">  


input type = "checkbox" checked by value, do not explain the method selected by value - html / css language columns: html.css - red and black coalition
https://www.2cto.com/kf/201801/710664.html

Guess you like

Origin www.cnblogs.com/yaolei0422/p/12022573.html