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>

原文地址:https://www.cnblogs.com/Cuiy/p/3517461.html