Javascript UUID Technology

Source: Internet
Author: User
Tags button type

This is mainly used when the selector filters duplicate elements.

Three possible methods are involved: sourceindex, uniqueid, and custom UUID.

Sourceindex obtains the order in which an element node appears on the page, that is, its index number in the Document. All set. To accurately obtain the sequential position, if an element node is inserted before it, it must be added. In other words, it is dynamically allocated and repeated computing is required each time. Note: IE only, read-only.

Uniqueid is also a read-only attribute of IE only. This attribute is not fixed in the element node as early as possible. The uniqueid is assigned to the entire page only when we access it for the first time. This means that if we use it for selector filtering, it may be slow for the first time. In addition, the document object also has this attribute, but its meaning is completely different from that of other HTML uniqueid attributes. Each time we call document. uniqueid, the system returns a new uniqueid value.

 
Window. onload = function () {alert (document. uniqueid) // Note: IE only alert (document. uniqueid) Alert (document. uniqueid )}

<Br/> <! Doctype HTML> <br/> <HTML lang = "en"> <br/> <pead> <br/> <meta charset = "UTF-8"/> <br/> <meta content = "Ie = 8" http-equiv = "X-UA-compatible"/> <br/> <title> uuid by situ zhengmei </title> <br/> <SCRIPT type = "text/JavaScript"> </P> <p> window. onload = function () {<br/> alert (document. uniqueid) <br/> alert (document. uniqueid) <br/> alert (document. uniqueid) <br/>}< br/> </SCRIPT> <br/> </pead> <br/> <body> </P> <p> </body> <br/> </ptml> <br/>

RunCode

These two items are both ie ony and can only be used for htmldocument. Therefore, we are destined to design a universal solution. See how jquery is implemented:

VaR expando = "jquery" + now (), UUID = 0, // ************************************ VaR id = ELEM [expando]

However, in IE, some elements may encounter errors when adding custom attributes, such as object, applet, and embed. This is cool.

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.