组合排列算法 算法js 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个在js就可以处理的吧 吧html贴出来 <div class="flash-indicator-container layer" id="FlashOptionContainer"> <div id="FlashIndicatorContainer"> <div class="group clearfix"> <label for="pv_count"> <input name="pv_count" value="pv_count" type="checkbox" title="浏览量(PV)" checked="checked" id="pv_count"> 浏览量(PV) </label> <label for="visitor_count"> <input name="visitor_count" value="visitor_count" type="checkbox" title="访客数(UV)" id="visitor_count"> 访客数(UV) </label> <label for="ip_count"> <input name="ip_count" value="ip_count" type="checkbox" title="IP数" id="ip_count"> IP数 </label> </div> <div class="separator"></div> <div class="group clearfix"> <label for="bounce_ratio"> <input name="bounce_ratio" value="bounce_ratio" type="checkbox" title="跳出率" id="bounce_ratio"> 跳出率 </label> <label for="avg_visit_time"> <input name="avg_visit_time" value="avg_visit_time" type="checkbox" title="平均访问时长" id="avg_visit_time"> 平均访问时长 </label> </div> </div> <div id="FlashTip" class="text"> (可同时选择<span id="MaxFlashIndicatorNum" class="max-flash-indicator-num">2</span>项) </div> </div> $('checkbox选择器').click(function(){ if(this.checked&&$('checkbox选择器:checked').size()>2)$('checkbox选择器:checked').not(this).attr('checked',false);}) <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript"> var chb = new Array(); $(document).ready(function(){ $.each($(":checkbox"),function(){ $(this).click(function(){ var thisName = $(this).attr('name'); if(chb.length >= 2){ chb.shift(); chb.push(thisName); }else{ chb.push(thisName); } console.log(chb) }) }) }) </script></head><body> <div> <input type="checkbox" value="1" name="aa" /> 浏览量 <input type="checkbox" value="1" name="bb" /> 访问次数 <input type="checkbox" value="1" name="cc" /> 访问数 <input type="checkbox" value="1" name="dd" /> 跳出率 <input type="checkbox" value="1" name="ee" /> 转化率 <input type="checkbox" value="1" name="ff" /> IP数 <input type="checkbox" value="1" name="ll" /> 平均访问时长 <input type="checkbox" value="1" name="mm" /> 平均访问次数 </div></body></html> 版主,用了这段代码没效果我的js代码如下:$('checkbox[name=tangram-flash-indicator]').on('click',function(){ if(this.checked&&$('checkbox[name=tangram-flash-indicator]:checked').size()>2)$('checkbox[name=tangram-flash-indicator]:checked').not(this).attr('checked',false); });html代码<div class="flash-indicator-container layer" id="FlashOptionContainer"> <div id="FlashIndicatorContainer"> <div class="group clearfix"> <label for="pv_count"> <input name="tangram-flash-indicator" value="pv_count" type="checkbox" title="浏览量(PV)" checked="checked" id="pv_count"> 浏览量(PV) </label> <label for="visitor_count"> <input name="tangram-flash-indicator" value="visitor_count" type="checkbox" title="访客数(UV)" id="visitor_count"> 访客数(UV) </label> <label for="ip_count"> <input name="tangram-flash-indicator" value="ip_count" type="checkbox" title="IP数" id="ip_count"> IP数 </label> </div> <div class="separator"></div> <div class="group clearfix"> <label for="bounce_ratio"> <input name="tangram-flash-indicator" value="bounce_ratio" type="checkbox" title="跳出率" id="bounce_ratio"> 跳出率 </label> <label for="avg_visit_time"> <input name="tangram-flash-indicator" value="avg_visit_time" type="checkbox" title="平均访问时长" id="avg_visit_time"> 平均访问时长 </label> </div> </div> <div id="FlashTip" class="text"> (可同时选择<span id="MaxFlashIndicatorNum" class="max-flash-indicator-num">2</span>项) </div> </div> 你导入jquery没有。。<div class="flash-indicator-container layer" id="FlashOptionContainer"> <div id="FlashIndicatorContainer"> <div class="group clearfix"> <label for="pv_count"> <input name="pv_count" value="pv_count" type="checkbox" title="浏览量(PV)" checked="checked" id="pv_count"> 浏览量(PV) </label> <label for="visitor_count"> <input name="visitor_count" value="visitor_count" type="checkbox" title="访客数(UV)" id="visitor_count"> 访客数(UV) </label> <label for="ip_count"> <input name="ip_count" value="ip_count" type="checkbox" title="IP数" id="ip_count"> IP数 </label> </div> <div class="separator"></div> <div class="group clearfix"> <label for="bounce_ratio"> <input name="bounce_ratio" value="bounce_ratio" type="checkbox" title="跳出率" id="bounce_ratio"> 跳出率 </label> <label for="avg_visit_time"> <input name="avg_visit_time" value="avg_visit_time" type="checkbox" title="平均访问时长" id="avg_visit_time"> 平均访问时长 </label> </div> </div> <div id="FlashTip" class="text"> (可同时选择<span id="MaxFlashIndicatorNum" class="max-flash-indicator-num">2</span>项) </div> </div><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script> $(function () { $('#FlashOptionContainer input').click(function () { if (this.checked && $('#FlashOptionContainer input:checked').size() > 2) $('#FlashOptionContainer input:checked').not(this).attr('checked', false); }) });</script> Quote: 引用 6 楼 showbo 的回复:上面的这段页面代码是点击某个div弹出来的。js已经导入了 你要在弹出层后再绑定事件,要不改为live动态绑定 你要在弹出层后再绑定事件,要不改为live动态绑定$('checkbox[name=tangram-flash-indicator]').on('click',function(){if(this.checked&&$('checkbox[name=tangram-flash-indicator]:checked').size()>2)$('checkbox[name=tangram-flash-indicator]:checked').not(this).attr('checked',false);});用的1.9版本的jquery库,已经用on绑定了 $('checkbox[name=tangram-flash-indicator]')[type=checkbox][name=tangram-flash-indicator] 我帮你做了一个例子,你运行试试<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><script language="javascript" type="text/javascript" src="jquery.js"></script> <title></title></head><body><script type="text/javascript" language="javascript">$(function(){$(".c").bind("click", function () { var num=0; $('.c').each(function () { if ($(this)[0].checked == true) { num = num +1; }}); if(num>2) { $('.c').each(function () { $(this)[0].checked = false;}); } });});</script><input type="checkbox" class="c" value="100" />$100<input type="checkbox" class="c" value="50"/>$50<input type="checkbox" class="c" value="150"/>$150</body></html> Quote: 引用 4 楼 microlab2009 的回复:引用了这段代码,修改了下差不多达到了要求的功能。还差一点就是当选中只有一个的时候,点击的时候不要取消。代码如下<script type="text/javascript">var chb = new Array();$(document).ready(function(){ $("#FlashIndicatorContainer .group input").on('click',function(){ var thisName = $(this).attr('name'); $("#FlashIndicatorContainer .group input").each(function(){ var n= $(this).attr('name'); if(!chb.in_array(n) && n != thisName && $(this).attr('checked') == 'checked') chb.push(n); }); if($(this).attr('checked') == 'checked') $(this).attr('checked',false); else $(this).attr('checked','checked'); if($(this).attr('checked') == 'checked') { if(chb.length >= 2){ chb.shift(); chb.push(thisName); }else{ chb.push(thisName); } } else { chb.remove(thisName); } $("#FlashIndicatorContainer .group input").each(function(){ var name = $(this).attr('name'); if(chb.in_array(name)) { $(this).attr('checked','checked'); } else { $(this).attr('checked',false); } }); }); })Array.prototype.in_array = function(e) { for(i=0;i<this.length && this[i]!=e;i++); return !(i==this.length); }Array.prototype.indexOf = function(val) { for (var i = 0; i < this.length; i++) { if (this[i] == val) return i; } return -1;};Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); }};</script> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript"> var chb = new Array(); var nameArr = new Array(); $(document).ready(function(){ $("#FlashIndicatorContainer .group input").each(function(){ nameArr.push($(this).attr('name')); $(this).click(function(){ var thisName = $(this).attr('name'); if($(this).attr('checked')){ if(chb.length >= 2){ chb.shift(); chb.push(thisName); $("input").attr('checked',false); for(var n=0;n<nameArr.length;n++){ if($.inArray(chb[n],nameArr) != -1 && chb[n] != 'undefined'){ console.log(nameArr[$.inArray(chb[n],nameArr)]) $("input[name='"+nameArr[$.inArray(chb[n],nameArr)]+"']").attr('checked',true); } } }else{ chb.push(thisName); } } else { chb.remove(thisName); } }) }); }) Array.prototype.in_array = function(e) { for(i=0;i<this.length && this[i]!=e;i++); return !(i==this.length); } Array.prototype.indexOf = function(val) { for (var i = 0; i < this.length; i++) { if (this[i] == val) return i; } return -1; }; Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); } }; </script></head><body> <div class="flash-indicator-container layer" id="FlashOptionContainer"> <div id="FlashIndicatorContainer"> <div class="group clearfix"> <label for="pv_count"> <input name="pv_count" value="pv_count" type="checkbox" title="浏览量(PV)" id="pv_count"> 浏览量(PV) </label> <label for="visitor_count"> <input name="visitor_count" value="visitor_count" type="checkbox" title="访客数(UV)" id="visitor_count"> 访客数(UV) </label> <label for="ip_count"> <input name="ip_count" value="ip_count" type="checkbox" title="IP数" id="ip_count"> IP数 </label> </div> <div class="separator"></div> <div class="group clearfix"> <label for="bounce_ratio"> <input name="bounce_ratio" value="bounce_ratio" type="checkbox" title="跳出率" id="bounce_ratio"> 跳出率 </label> <label for="avg_visit_time"> <input name="avg_visit_time" value="avg_visit_time" type="checkbox" title="平均访问时长" id="avg_visit_time"> 平均访问时长 </label> </div> </div> <div id="FlashTip" class="text"> (可同时选择<span id="MaxFlashIndicatorNum" class="max-flash-indicator-num">2</span>项) </div> </div></body></html> js setTimeout问题 爸爸、妈妈、儿子、女儿、警察、土匪过河游戏 在页面中如果取得dtree对象,急!还在加班 散分 关于innerHTML JavasScript怪异执行结果! 求教各位高手一个问题 请问,怎么打印一个框架中的某一个框架页? 怎么样判断textarea的值为空,在Javascript里面 怎样获取光标在文本中的位置? 一个简单的easyui datagrid初始化列名的问题 js脚本开发用什么工具呢?
<div id="FlashIndicatorContainer">
<div class="group clearfix">
<label for="pv_count">
<input name="pv_count" value="pv_count" type="checkbox" title="浏览量(PV)" checked="checked" id="pv_count">
浏览量(PV)
</label>
<label for="visitor_count">
<input name="visitor_count" value="visitor_count" type="checkbox" title="访客数(UV)" id="visitor_count">
访客数(UV)
</label>
<label for="ip_count">
<input name="ip_count" value="ip_count" type="checkbox" title="IP数" id="ip_count">
IP数
</label>
</div>
<div class="separator"></div>
<div class="group clearfix">
<label for="bounce_ratio">
<input name="bounce_ratio" value="bounce_ratio" type="checkbox" title="跳出率" id="bounce_ratio">
跳出率
</label>
<label for="avg_visit_time">
<input name="avg_visit_time" value="avg_visit_time" type="checkbox" title="平均访问时长" id="avg_visit_time">
平均访问时长
</label>
</div>
</div>
<div id="FlashTip" class="text">
(可同时选择<span id="MaxFlashIndicatorNum" class="max-flash-indicator-num">2</span>项)
</div>
</div>
if(this.checked&&$('checkbox选择器:checked').size()>2)$('checkbox选择器:checked').not(this).attr('checked',false);
})
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var chb = new Array();
$(document).ready(function(){
$.each($(":checkbox"),function(){
$(this).click(function(){
var thisName = $(this).attr('name');
if(chb.length >= 2){
chb.shift();
chb.push(thisName);
}else{
chb.push(thisName);
}
console.log(chb)
})
})
})
</script></head>
<body>
<div>
<input type="checkbox" value="1" name="aa" /> 浏览量 <input type="checkbox" value="1" name="bb" /> 访问次数 <input type="checkbox" value="1" name="cc" /> 访问数 <input type="checkbox" value="1" name="dd" /> 跳出率 <input type="checkbox" value="1" name="ee" /> 转化率 <input type="checkbox" value="1" name="ff" /> IP数 <input type="checkbox" value="1" name="ll" /> 平均访问时长 <input type="checkbox" value="1" name="mm" /> 平均访问次数
</div>
</body>
</html>
版主,用了这段代码没效果
我的js代码如下:
$('checkbox[name=tangram-flash-indicator]').on('click',function(){
if(this.checked&&$('checkbox[name=tangram-flash-indicator]:checked').size()>2)$('checkbox[name=tangram-flash-indicator]:checked').not(this).attr('checked',false);
});html代码
<div class="flash-indicator-container layer" id="FlashOptionContainer">
<div id="FlashIndicatorContainer">
<div class="group clearfix">
<label for="pv_count">
<input name="tangram-flash-indicator" value="pv_count" type="checkbox" title="浏览量(PV)" checked="checked" id="pv_count">
浏览量(PV)
</label>
<label for="visitor_count">
<input name="tangram-flash-indicator" value="visitor_count" type="checkbox" title="访客数(UV)" id="visitor_count">
访客数(UV)
</label>
<label for="ip_count">
<input name="tangram-flash-indicator" value="ip_count" type="checkbox" title="IP数" id="ip_count">
IP数
</label>
</div>
<div class="separator"></div>
<div class="group clearfix">
<label for="bounce_ratio">
<input name="tangram-flash-indicator" value="bounce_ratio" type="checkbox" title="跳出率" id="bounce_ratio">
跳出率
</label>
<label for="avg_visit_time">
<input name="tangram-flash-indicator" value="avg_visit_time" type="checkbox" title="平均访问时长" id="avg_visit_time">
平均访问时长
</label>
</div>
</div>
<div id="FlashTip" class="text">
(可同时选择<span id="MaxFlashIndicatorNum" class="max-flash-indicator-num">2</span>项)
</div>
</div>
<div id="FlashIndicatorContainer">
<div class="group clearfix">
<label for="pv_count">
<input name="pv_count" value="pv_count" type="checkbox" title="浏览量(PV)" checked="checked" id="pv_count">
浏览量(PV)
</label>
<label for="visitor_count">
<input name="visitor_count" value="visitor_count" type="checkbox" title="访客数(UV)" id="visitor_count">
访客数(UV)
</label>
<label for="ip_count">
<input name="ip_count" value="ip_count" type="checkbox" title="IP数" id="ip_count">
IP数
</label>
</div>
<div class="separator"></div>
<div class="group clearfix">
<label for="bounce_ratio">
<input name="bounce_ratio" value="bounce_ratio" type="checkbox" title="跳出率" id="bounce_ratio">
跳出率
</label>
<label for="avg_visit_time">
<input name="avg_visit_time" value="avg_visit_time" type="checkbox" title="平均访问时长" id="avg_visit_time">
平均访问时长
</label>
</div>
</div>
<div id="FlashTip" class="text">
(可同时选择<span id="MaxFlashIndicatorNum" class="max-flash-indicator-num">2</span>项)
</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function () {
$('#FlashOptionContainer input').click(function () {
if (this.checked && $('#FlashOptionContainer input:checked').size() > 2) $('#FlashOptionContainer input:checked').not(this).attr('checked', false);
})
});
</script>
你要在弹出层后再绑定事件,要不改为live动态绑定
你要在弹出层后再绑定事件,要不改为live动态绑定
$('checkbox[name=tangram-flash-indicator]').on('click',function(){
if(this.checked&&$('checkbox[name=tangram-flash-indicator]:checked').size()>2)$('checkbox[name=tangram-flash-indicator]:checked').not(this).attr('checked',false);
});用的1.9版本的jquery库,已经用on绑定了
[type=checkbox][name=tangram-flash-indicator]
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script language="javascript" type="text/javascript" src="jquery.js"></script>
<title></title>
</head>
<body>
<script type="text/javascript" language="javascript">
$(function(){$(".c").bind("click", function () {
var num=0;
$('.c').each(function () {
if ($(this)[0].checked == true) {
num = num +1;
}});
if(num>2)
{
$('.c').each(function () {
$(this)[0].checked = false;});
}
});
});</script><input type="checkbox" class="c" value="100" />$100
<input type="checkbox" class="c" value="50"/>$50
<input type="checkbox" class="c" value="150"/>$150
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var chb = new Array();
var nameArr = new Array();
$(document).ready(function(){
$("#FlashIndicatorContainer .group input").each(function(){
nameArr.push($(this).attr('name')); $(this).click(function(){
var thisName = $(this).attr('name');
if($(this).attr('checked')){
if(chb.length >= 2){
chb.shift();
chb.push(thisName);
$("input").attr('checked',false);
for(var n=0;n<nameArr.length;n++){
if($.inArray(chb[n],nameArr) != -1 && chb[n] != 'undefined'){
console.log(nameArr[$.inArray(chb[n],nameArr)])
$("input[name='"+nameArr[$.inArray(chb[n],nameArr)]+"']").attr('checked',true);
}
}
}else{
chb.push(thisName);
}
}
else
{
chb.remove(thisName);
} })
});
})
Array.prototype.in_array = function(e)
{ for(i=0;i<this.length && this[i]!=e;i++);
return !(i==this.length);
}
Array.prototype.indexOf = function(val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
</script>
</head>
<body>
<div class="flash-indicator-container layer" id="FlashOptionContainer">
<div id="FlashIndicatorContainer">
<div class="group clearfix">
<label for="pv_count">
<input name="pv_count" value="pv_count" type="checkbox" title="浏览量(PV)" id="pv_count">
浏览量(PV)
</label>
<label for="visitor_count">
<input name="visitor_count" value="visitor_count" type="checkbox" title="访客数(UV)" id="visitor_count">
访客数(UV)
</label>
<label for="ip_count">
<input name="ip_count" value="ip_count" type="checkbox" title="IP数" id="ip_count">
IP数
</label>
</div>
<div class="separator"></div>
<div class="group clearfix">
<label for="bounce_ratio">
<input name="bounce_ratio" value="bounce_ratio" type="checkbox" title="跳出率" id="bounce_ratio">
跳出率
</label>
<label for="avg_visit_time">
<input name="avg_visit_time" value="avg_visit_time" type="checkbox" title="平均访问时长" id="avg_visit_time">
平均访问时长
</label>
</div>
</div>
<div id="FlashTip" class="text">
(可同时选择<span id="MaxFlashIndicatorNum" class="max-flash-indicator-num">2</span>项)
</div>
</div>
</body>
</html>