<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><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> <br> <br> </div>