Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between id and name in html

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what is the difference between id and name in html". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Differences: 1. The value of the id attribute is case-sensitive and each id value should be unique, while the name attribute is not unique and its value can be reused. 2. For different purposes, the id attribute can be used as an anchor reference or an ID selector, while the name attribute is used in the form to submit information.

The operating environment of this tutorial: windows7 system, HTML5 version, Dell G3 computer.

In html, both the id attribute and the name attribute provide identifiers that represent HTML element tags. So what's the difference between them? This article will give you a brief comparison between the id attribute and the name attribute, and introduce what is the difference between the id attribute and the name attribute. I hope it will be helpful to you.

The id property in html

We use the id attribute to identify a unique HTML element, which can be used as an anchor reference (URL with a # symbol) in URL or as an ID selector in css to style that element. You can also find the element by the value of the id attribute in javascript, using getElementById (), and manipulate the element. Example:

Test the text! Test the text!

Test the text! Test the text!

Document.getElementById ("p2") .style.color = "red"

The id attribute is generally compatible and is valid for any element. And the value of the id attribute is case-sensitive, and each id value should be unique. Example:

Div tag, id value is a p label, id value is A

# a {color: red;} # A {color: pink;}

Effect picture:

The name property in html

The name attribute is also used to identify the HTML element, but it does not have a unique row, and its value can be reused, for example: radio button

Do you like fruit best? Apples, peaches, bananas and pears

Effect picture:

As shown in the example above, the name attribute is often used in forms to submit information; it only works on tag elements such as a, form, iframe, img, map, input, select, textarea, and so on.

The name attribute can be found using getElementsByName () in javascript; it cannot be referenced in CSS or URL. Example:

Function getElements () {var x=document.getElementsByName ("myInput"); alert (x.length);}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report