The method of obtaining the same name value of the HTML tag

Source: Internet
Author: User

Sometimes there may be multiple IDs and name values in the include reference to the JSP, and if JS uses that ID or name, an error occurs. In this case, the same code can be separated by the Div, each div is set a special ID, and then the ID value of the name of the div under the tag, so it is unique.

Like what:

<!doctype html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> test Page </title>
<script type= "Text/javascript" src= "Jquery.js" ></script>
<body>
<table>
<tr>
<TD name= "TD1" >aaa</td>
<TD name= "TD2" >bbb</td>
</tr>
</table>
<table>
<tr>
<TD name= "TD1" >ddd</td>
<TD name= "TD2" >eee</td>
</tr>
</table>
</body>

Can be changed to the following, and through jquery to get the corresponding object

<!doctype html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> test Page </title>
<script type= "Text/javascript" src= "Jquery.js" ></script>
<body>
<div id= "Div1" >
<table>
<tr>
&LT;TD name= "TD1" >aaa</td>
&LT;TD name= "TD2" >bbb</td>
</tr>
</table>
</div>
<div id= "Div2" >
<table>
<tr>
&LT;TD name= "TD1" >ddd</td>
&LT;TD name= "TD2" >eee</td>
</tr>
</table>
</div>
<script>
$ ("#div1 td[name^= ' TD1 ')". html (); Read
$ ("#div1 td[name^= ' TD1 ')". html (' CCC '); Set up
$ ("#div2 td[name^= ' TD1 ')". html (); Read
$ ("#div2 td[name^= ' TD1 ')". html (' CCC '); Set up
</script>
</body>

This can be separated by the DIV tag, it is also convenient to get the value

The method of obtaining the same name value of the HTML tag

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.