<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<style>
*{margin:0;padding:0;}
ul,li{
list-style:none;
}
.work,.opc,.age,.stu{
500px;
height:30px;
}
.work-item,.opc-item,.age-item,.stu-item{
50px;
text-align:center;
background-color:pink;
}
.all{
background-color:blue;
color:#fff;
}
</style>
<body>
<div class="work">
<span class="all">300</span>
<span class="work-item mycode">3001</span>
<span class="work-item mycode">3002</span>
<span class="work-item mycode">3003</span>
</div>
<div class="opc">
<span class="all">400</span>
<span class="opc-item mycode">4001</span>
<span class="opc-item mycode">4002</span>
<span class="opc-item mycode">4003</span>
</div>
<div class="age">
<span class="all">500</span>
<span class="age-item mycode">5001</span>
<span class="age-item mycode">5002</span>
<span class="age-item mycode">5003</span>
</div>
<div class="stu">
<span class="all">600</span>
<span class="stu-item mycode">6001</span>
<span class="stu-item mycode">6002</span>
<span class="stu-item mycode">6003</span>
</div>
<script>
var allTags=[];
var tagcodes=[];
// 查找指定位置
Array.prototype.indexOf = function(val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
//delete one
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
//数组去重
Array.prototype.unique3 = function(){
var res = [];
var json = {};
for(var i = 0; i < this.length; i++){
if(!json[this[i]]){
res.push(this[i]);
json[this[i]] = 1;
}
}
return res;
}
// gel all
function getAll(){
$('.all').click(function(){
allTags.push($(this).html());
allTags = allTags.unique3();
console.log(allTags);
//console.log($(this).html())
for(var i=0;i<allTags.length;i++){
if(tagcodes.indexOf(allTags[i]!=-1)){
tagcodes.splice(tagcodes.indexOf(allTags[i]) ,1);
}
}
console.log(tagcodes);
console.log(allTags)
console.dir('all is'+allTags)
})
}
//选择标签 单选
function getTags(){
$('.mycode').click(function(){
//console.dir($(this).html());
tagcodes.push($(this).html()) ;
tagcodes=tagcodes.unique3();
console.log(tagcodes)
})
}
$(function(){
getAll();
getTags();
var t = 1324;
var bn = 12235;
//console.log(bn.indexOf(1))
})
</script>
</body>
</html>