搜索多选-js
程序员文章站
2022-05-25 18:30:27
...
<form action="" id="star_f_search" method="GET">
<input type="hidden" id="region_val" name="region_val" value="4|2">
<input type="hidden" id="con_val" name="con_val" value="3|8|4|5|7">
<input type="hidden" id="char_val" name="char_val" value="G|H|K">
</form>
<div id="star_region" class="item">
<a v="1" href="javascript:;">内地</a>
<a v="2" style="color:rgb(33, 110, 201)" href="javascript:;">港台</a>
<a v="3" href="javascript:;">亚洲</a>
<a v="4" style="color:rgb(33, 110, 201)" href="javascript:;">欧美</a>
<a v="5" href="javascript:;">其它</a>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#star_region a").bind('click',function(){
checkSelectVal($("#region_val"),$(this));
});
})
function checkSelectVal(obj,selectObj){
var temp = obj.val();
var val = selectObj.attr('v');
var field = new Array();
if(temp == ''){
obj.val(val);
selectObj.css('color','rgb(33, 110, 201)');
}else{
field = temp.split('|');
var mark = -1;
for(var key in field){
if(field[key] == val){
mark = key;break;
}
}
if(mark != -1){
field.splice(key, 1);
selectObj.css('color','');
}else{
field.push(val);
selectObj.css('color','rgb(33, 110, 201)');
}
var str = field.join('|');
obj.val(str);
}
}
</script>
<input type="hidden" id="region_val" name="region_val" value="4|2">
<input type="hidden" id="con_val" name="con_val" value="3|8|4|5|7">
<input type="hidden" id="char_val" name="char_val" value="G|H|K">
</form>
<div id="star_region" class="item">
<a v="1" href="javascript:;">内地</a>
<a v="2" style="color:rgb(33, 110, 201)" href="javascript:;">港台</a>
<a v="3" href="javascript:;">亚洲</a>
<a v="4" style="color:rgb(33, 110, 201)" href="javascript:;">欧美</a>
<a v="5" href="javascript:;">其它</a>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#star_region a").bind('click',function(){
checkSelectVal($("#region_val"),$(this));
});
})
function checkSelectVal(obj,selectObj){
var temp = obj.val();
var val = selectObj.attr('v');
var field = new Array();
if(temp == ''){
obj.val(val);
selectObj.css('color','rgb(33, 110, 201)');
}else{
field = temp.split('|');
var mark = -1;
for(var key in field){
if(field[key] == val){
mark = key;break;
}
}
if(mark != -1){
field.splice(key, 1);
selectObj.css('color','');
}else{
field.push(val);
selectObj.css('color','rgb(33, 110, 201)');
}
var str = field.join('|');
obj.val(str);
}
}
</script>
上一篇: Python 文件操作实现代码