87,920
社区成员
发帖
与我相关
我的任务
分享
<!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>
<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>
<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>
<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>
<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>
<!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>
$('checkbox选择器').click(function(){
if(this.checked&&$('checkbox选择器:checked').size()>2)$('checkbox选择器:checked').not(this).attr('checked',false);
})
<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>