<input type="checkbox" name="chk[]" id="chkA" value="0"/>1
<input type="checkbox" name="chk[]" id="chkB" value="1"/>2
<input type="checkbox" name="chk[]" id="chkC" value="2"/>3
<input type="checkbox" name="chk[]" id="chkD" value="3"/>4
<input type="checkbox" name="chk[]" id="chkE" value="4"/>5
<input type="checkbox" name="chk[]" id="chkF" value="5"/>6
<input type="checkbox" name="chk[]" id="chkG" value="6"/>7
<script type="text/javascript">
<!--
var arr = [];
(function(){
var ochk = document.getElementsByName('chk[]');
for(var i = 0, len = ochk.length; i < len; i++){
ochk[i].onclick = function(){
if(this.checked){
if(arr.length >= 2){
ochk[arr[1]].checked = false;
arr[1] = this.value;
}else{
arr.push(this.value);
}
}else{
arr.shift();
}
}
}
})();
//-->
</script>
<input type="checkbox" name="chk[]" id="chkB" value="1"/>2
<input type="checkbox" name="chk[]" id="chkC" value="2"/>3
<input type="checkbox" name="chk[]" id="chkD" value="3"/>4
<input type="checkbox" name="chk[]" id="chkE" value="4"/>5
<input type="checkbox" name="chk[]" id="chkF" value="5"/>6
<input type="checkbox" name="chk[]" id="chkG" value="6"/>7
<script type="text/javascript">
<!--
var arr = [];
(function(){
var ochk = document.getElementsByName('chk[]');
for(var i = 0, len = ochk.length; i < len; i++){
ochk[i].onclick = function(){
if(this.checked){
if(arr.length >= 2){
ochk[arr[1]].checked = false;
arr[1] = this.value;
}else{
arr.push(this.value);
}
}else{
arr.shift();
}
}
}
})();
//-->
</script>
<input type="checkbox" name="chk[]" id="chkA" value="0"/>1
<input type="checkbox" name="chk[]" id="chkB" value="1"/>2
<input type="checkbox" name="chk[]" id="chkC" value="2"/>3
<input type="checkbox" name="chk[]" id="chkD" value="3"/>4
<input type="checkbox" name="chk[]" id="chkE" value="4"/>5
<input type="checkbox" name="chk[]" id="chkF" value="5"/>6
<input type="checkbox" name="chk[]" id="chkG" value="6"/>7
<script type="text/javascript">
<!--
var arr = [];
(function(){
var ochk = document.getElementsByName('chk[]');
for(var i = 0, len = ochk.length; i < len; i++){
ochk[i].onclick = function(){
if(this.checked){
if(arr.length >= 1){
ochk[arr[0]].checked = false;
arr[0] = this.value;
}else{
arr.push(this.value);
}
}else{
arr.shift();
}
}
}
})();
//-->
</script>
大概知道LZ的意思了
<input type="checkbox" name="chk[]" id="chkA" value="0"/>1
<input type="checkbox" name="chk[]" id="chkB" value="1"/>2
<input type="checkbox" name="chk[]" id="chkC" value="2"/>3
<input type="checkbox" name="chk[]" id="chkD" value="3"/>4
<input type="checkbox" name="chk[]" id="chkE" value="4"/>5
<input type="checkbox" name="chk[]" id="chkF" value="5"/>6
<input type="checkbox" name="chk[]" id="chkG" value="6"/>7
<script type="text/javascript">
<!--
var obj;
var ochk = document.getElementsByName('chk[]');
for(var i=0;i<ochk.length;i++){
ochk[i].onclick=function(){
if(obj!=null){
obj.checked=false;
}
obj=this;
}
}//-->
</script>换了个写法,LZ你看看
<input type="checkbox" name="chk[]" id="chkA" value="0"/>0
<input type="checkbox" name="chk[]" id="chkB" value="1"/>1
<input type="checkbox" name="chk[]" id="chkC" value="2"/>2
<input type="checkbox" name="chk[]" id="chkD" value="3"/>3
<input type="checkbox" name="chk[]" id="chkE" value="4"/>4
<input type="checkbox" name="chk[]" id="chkF" value="5"/>5
<input type="checkbox" name="chk[]" id="chkG" value="6"/>6
</body>
<script type="text/javascript">
<!--
var arr = [];// js 数组初始化
(
function(){
var ochk = document.getElementsByName('chk[]');
for(var i = 0, len = ochk.length; i < len; i++){
ochk[i].onclick = function(){
if(this.checked){
if(arr.length >= 3){
ochk[arr[2]].checked = false;
arr[2] = this.value;
alert(arr[0]+" "+arr[1]+" "+arr[2])
}else{
arr.push(this.value);// 数组赋值
}
}else{
//arr.shift();// 删除数组第一个元素
arr.pop();// 删除数组最后一个元素
}
}
}
}
)();
//-->
</script>