JS string to repeat the ID's implementation code

Source: Internet
Author: User
Recently due to the need for us to delete the relevant ID of the duplicate, one is the client a background program, here to share the next JS to repeat the ID of the implementation code <textarea id="runcode71352"><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title>js to repeat id</title> </pead> <body> <script type=" Text/javascript "> String.prototype.repeatOpt = function () {var str = this +" ", Objstr =" "; for (var i = 0; i < this.length i++) {var s = str[i]; var newstr = str.replace (S, '); var j = Newstr.indexof (s); if (j = = 1) {objstr + = s+ ","; } return OBJSTR; Alert ("1,2,2,3,4,4,5,6". repeatopt ()); </script> </body> </ptml></textarea>


[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]


I often use the code:

&lt;! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "&gt; &lt;html xmlns=" http://www.w3.org/1999/xhtml "&gt; &lt;head&gt; &lt;meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/&gt; &lt;title&gt;js Remove duplicate id&lt;/title&gt; &lt;script type=" Text/javascript "&gt; Function $Obj ( objname) {return document.getElementById (objname); ///For the user to invoke function trim (s) {return trimright Trimleft (s)); //Remove the left blank function trimleft (s) {if (s = = null) {return ""; var whitespace = new String ("TNR"); var str = new String (s); if (Whitespace.indexof (Str.charat (0))!=-1) {var j=0, i = str.length; while (J &lt; i &amp;&amp; Whitespace.indexof (Str.charat (j))!=-1) {j + +; str = str.substring (j, I); return str; //Remove the blank function on the right trimright (s) {if (s = = null) return ""; var whitespace = new String ("TNR"); var str = new String (s); if (Whitespace.indexof (Str.charat (str.length-1))!=-1) {VAr i = str.length-1; while (i &gt;= 0 &amp;&amp; whitespace.indexof (str.charat (i))!=-1) {i--; str = str.substring (0, i+1); return str; function Doxgid () {Document.form1.likeid.value = Trim (document.form1.likeid.value.replace new RegExp (', ', ' GM '), ', ' )); Document.form1.likeid.value = Trim (Document.form1.likeid.value.replace (New RegExp (', "GM"), ', ')); Xgidcheck (); function Xgidcheck () {if (document.form1.likeid.value!= "") {var arr1 = unique (Document.form1.likeid.value.split (",") ); Document.form1.likeid.value=arr1.join (","); }//Go repeat array function unique (data) {data = Data | | []; var a = {}; len = data.length; for (var i=0 i&lt;len;i++) {var v = data[i]; if (typeof (A[v]) = = ' undefined ') {a[v] = 1; } }; data.length=0; for (var i in a) {data[data.length] = i; } return data; }//Thematic enhancement function Doxgid2 (theitem) {var theform= $Obj (Theitem); Theform.value = Trim (Theform.value.replace (New RegExp (', ', "GM"), ', ')); Theform.value = Trim (theform.vAlue.replace (New RegExp (', "GM"), ', '); Xgidcheck2 (theform); function Xgidcheck2 (theform) {if (theform.value!= "") {var arr1 = unique (Theform.value.split (",")); Theform.value=arr1.join (","); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name= "Form1" &gt; Instance one: A separate form validation &lt;input name= "Likeid "Type=" text "id=" Likeid "size=" "onblur=" Doxgid () "value=" 1,2,3,4,5,6,4,5,6 "&gt; Instance two: Multiple forms validation &lt;textarea n Ame= "Jb51id" rows= "3" id= "Jb51id" style= "width:90%" onblur= "Doxgid2" (' Jb51id ') "&gt;1,2,3,4,5,6,4,5,6&lt;/textarea &gt; First position the mouse inside the form, and then leave to trigger it. OnBlur &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;


[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.