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:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title>js Remove duplicate id</title> <script type=" Text/javascript "> 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 < i && 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 >= 0 && 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<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 (","); } </script> </head> <body> <form name= "Form1" > Instance one: A separate form validation <input name= "Likeid "Type=" text "id=" Likeid "size=" "onblur=" Doxgid () "value=" 1,2,3,4,5,6,4,5,6 "> Instance two: Multiple forms validation <textarea n Ame= "Jb51id" rows= "3" id= "Jb51id" style= "width:90%" onblur= "Doxgid2" (' Jb51id ') ">1,2,3,4,5,6,4,5,6</textarea > First position the mouse inside the form, and then leave to trigger it. OnBlur </form> </body> </html>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]