ji程序:
在这里有一点要注意就是将id作为数组下表时,后面减整形的时候就是按减法算,但要是加的话,这个加的含义就是字符串的连接而不是加法计算比如:
id="1"
id-1就是0
id+1就是11
所以要讲id先转换成整形parseInt(this.id);
window.onload = function(){
//复选框单选效果
var che = document.getElementsByName('attendance[]');
var id = 0;
for (var i=0; i <che.length; i++) {
che[i].onclick = function () {
id=parseInt(this.id);
if((this.id)%3==0&&this.checked==true){
document.getElementById(id+1).checked = false;
document.getElementById(id+2).checked = false;
} else if((this.id)%3==1&&this.checked==true){
document.getElementById(id-1).checked = false;
document.getElementById(id+1).checked = false;
} else if((this.id)%3==2&&this.checked==true){
document.getElementById(id-1).checked = false;
document.getElementById(id-2).checked = false;
}
}
}
}
html与php实现显示多行复选框
<?php
//复选框标号
$_tabIndex = 0;
可以放取数据库数据的PHP语句。一行一行取数据,决定有多少行
while(!!$_rows1=@mysql_fetch_array($_result1,MYSQL_ASSOC)){
$_a = $_tabIndex+1;
$_b = $_tabIndex+2;
?>
<tr>
<td><input type="checkbox" id="<?php echo $_tabIndex ?>" name="attendance[]" value="0" checked="checked"></input>出席
<input type="checkbox" id="<?php echo $_a ?>" name="attendance[]" value="1" ></input>请假
<input type="checkbox" id="<?php echo $_b ?>" name="attendance[]" value="2" ></input>缺勤
</td>
</tr>
<?php
$_tabIndex = $_tabIndex+3;
}
?>