<html>
<head>
<title>jq查询数组是否存在重复内容/jq判断是否存在哪些值</title>
</head>
<body>
<div class="FormBox">
<!-- autocomplete 属性是 HTML5 中的新属性 禁止浏览器表单自动填充 -->
<form class="formlist" autocomplete="off">
<input type="text" name="username" value="a">
</form>
<form class="formlist" autocomplete="off">
<input type="text" name="username" value="b">
</form>
<form class="formlist" autocomplete="off">
<input type="text" name="username" value="a">
</form>
<button onclick="submit()">查询</button>
</div>
<script src="jquery-1.7.1.js"></script>
<script>
var username = [];
function submit(){
$('.formlist').each(function(index,element){ //element-当前的元素,也可使用this选择器
var aa = $(this).find("input[name='username']").val();
username.push(aa);
});
console.log(username);
// 判断数组是否存在重复的值
var nary=username.sort();
for(var i=0;i<username.length;i++){
if (nary[i]==nary[i+1]){
console.log("数组重复内容:"+nary[i]);
}
}
// 判断同时存在已知固定的值
if(username.indexOf('a')>=0 && username.indexOf('a')>=0){
console.log('同时存在a和b');
}
}
</script>
</body>
</html>