<div class="codetitle"> <span><a style="CURSOR: pointer" data="20115" class="copybut" id="copybut20115" onclick="doCopy('code20115')"><u>複製程式碼</u></a></span> 代碼如下:</div> <div class="codebody" id="code20115"> <br> <br><br> <br> <br> <br><script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> <BR></script> <br><script> <BR>$(document).ready(function(){ <BR>$("button").click(function(){ <BR>var str=$("#org").val(); <BR>var arr=str.split(""); <BR>for(var i=0;arr.length-1>i;i ){ <BR>for(var j=i 1;j<arr.length;j ) { <BR>if(arr[j]==arr[i]){ <BR>alert(arr.length); <BR>arr.splice(j,1); //刪除之後,陣列長度隨之減少<BR>j--; <BR>} <BR>} <BR>} <br>alert(arr.toString()); <br>//$("#dl").val(arr.toString( ));//產生的字串由逗號隔開<br><br>$("#dl").val(arr.join(""));//產生的字串無分割符<BR> <BR>$("#dl").val(arr.join("-"));//join方法可指定產生的字串的分隔符號<BR>$("#dl").attr({ "style":""}); <BR>}) <BR>}); <BR></script> <br> <br> <br><input id="org" type="text" value="hhuummqqhhuummss"> <br><button type="button">去除重複</button> <br><input id="dl" type="text" style="display:none "> <br> </div>