In the past, obtaining dom elements was basically done through js's document.getElementById() or document.getElementByName or other methods or through jQ's selector. However, in fact, the name attribute of html can also be used to directly obtain dom elements. The code is as follows Shown:
<!DOCTYPE html> <html> <head> <script> function check(){ listForm.sel.checked=true; }</script></head><body><form name="listForm"> <input type="checkbox" name="sel"/></form><input type="button" value="button" onclick="check();"/> </body> </html>
Pressing the button key will cause the checkbox named sel in the form to be selected.
The above is the detailed content of Use the name attribute of html to get the dom element. For more information, please follow other related articles on the PHP Chinese website!