select下拉框去重複

上代碼:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>無題のページ</title>

<script src="script/jquery-1.9.1.js" type="text/javascript"></script>

<script type="text/javascript">
$(function() {
$("select").each(function(i, n) {
var options = "";
$(n).find("option").each(function(j, m) {
if (options.indexOf($(m)[0].outerHTML) == -1) {
options += $(m)[0].outerHTML;
}
});
$(n).html(options);
});
})
</script>

</head>
<body>
<select>
<option>1 </option>
<option>1 </option>
<option>2 </option>
<option>2 </option>
<option>3</option>
</select>
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章