如果我在jsp中有这样的复选框: form:checkbox path =“agreeToLegalAgreements”/ 它导致: input id =“agreeToLegalAgreements1”name =“agreeToLegalAgreements”type =“checkbox”value =“true”/ input type =“hidde
< form:checkbox path =“agreeToLegalAgreements”/>
它导致:
< input id =“agreeToLegalAgreements1”name =“agreeToLegalAgreements”type =“checkbox”value =“true”/>< input type =“hidden”name =“_ agreeToLegalAgreements”value =“on”/>
为什么ID会附加“1”?我问的原因是因为如果我想使用javascript选择此复选框,我必须硬编码“1”:
.的document.getElementById( ‘agreeToLegalAgreements1’)检查= TRUE;
例如,如果表单对象具有兴趣列表
Programming: <form:checkbox path="interests" value="Programming"/> Painting: <form:checkbox path="interests" value="Painting"/> Fishing: <form:checkbox path="interests" value="Fishing"/>
输出将是:
Programming: <input id="interests1" name="interests" type="checkbox" value="Programming"/> Painting: <input id="interests2" name="interests" type="checkbox" value="Painting"/> Fishing: <input id="interests3" name="interests" type="checkbox" value="Fishing"/>
(我省略了隐藏的空值输入)