Home > Web Front-end > HTML Tutorial > Use the name attribute of html to get the dom element

Use the name attribute of html to get the dom element

一个新手
Release: 2017-09-18 10:53:30
Original
2897 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template