开发者

How to get all the radio buttons with the same id?

开发者 https://www.devze.com 2023-01-04 13:46 出处:网络
I have a web form that have 5 radio button with the same id. How can I catch all the radio buttons in a vector from JavaS开发者_JS百科cript?You should use different ids or different names for html el

I have a web form that have 5 radio button with the same id.

How can I catch all the radio buttons in a vector from JavaS开发者_JS百科cript?


You should use different ids or different names for html elements. Also jquery helps you on this subject.

$(':radio') 

it helps you to select all radio elements on the page. You can do what you want with using Jquery.

here is the jquery source: http://code.jquery.com/jquery-1.4.2.min.js


Using same ID for more than one element on page is incorrect! use name attribute to group these buttons.


Element identifiers: the id = name [CS] This attribute assigns a name to an element. This name must be unique in a document. The id attribute assigns a unique identifier to an element (which may be verified by an SGML parser).

The id attribute has several roles in HTML:

As a style sheet selector. As a target anchor for hypertext links. As a means to reference a particular element from a script. As the name of a declared OBJECT element. For general purpose processing by user agents (e.g. for identifying fields when extracting data from HTML pages into a database, translating HTML documents into other formats, etc.).

http://www.w3.org/TR/html401/struct/global.html#adef-id

0

精彩评论

暂无评论...
验证码 换一张
取 消