<script language="javascript">
function check_all(form){
for(var i=0;i<form.elements.length-2;i++){
var e=form.elements[i];
e.checked=true;
}
}
function inverse(form){
for(var i=0;i<form.elements.length-2;i++){
var e=form.elements[i];
e.checked==true?e.checked=false:e.checked=true;
}
}
</script>
有如上js 代码,
<td colspan="2"><label>
<input type="button" name="checkbox4" id="checkbox4" value="全选" onclick="check_all(this.form)"/>
<input type="button" name="checkbox5" id="checkbox5" value="反选" onclick="inverse(this.form)"/>
<input type="submit" name="button" id="button" value="删除" />
</label></td>
用上面红字的语句调用时调用成功,而用如下代码,就是不用button,就直接用超链接来调用
<tr>
<td colspan="2"><label>
<a onclick="javascript:check_all(this.form);" href="#">全选</a>/
<a href="#" onclick="javascript:inverse(this.form);">反选</a> <input type="submit" name="button" id="button" value="删除" />
</label></td>
</tr>
上面这两句红的语句该怎么写写才能像上面的代码一样实现其功能???
function check_all(form){
for(var i=0;i<form.elements.length-2;i++){
var e=form.elements[i];
e.checked=true;
}
}
function inverse(form){
for(var i=0;i<form.elements.length-2;i++){
var e=form.elements[i];
e.checked==true?e.checked=false:e.checked=true;
}
}
</script>
有如上js 代码,
<td colspan="2"><label>
<input type="button" name="checkbox4" id="checkbox4" value="全选" onclick="check_all(this.form)"/>
<input type="button" name="checkbox5" id="checkbox5" value="反选" onclick="inverse(this.form)"/>
<input type="submit" name="button" id="button" value="删除" />
</label></td>
用上面红字的语句调用时调用成功,而用如下代码,就是不用button,就直接用超链接来调用
<tr>
<td colspan="2"><label>
<a onclick="javascript:check_all(this.form);" href="#">全选</a>/
<a href="#" onclick="javascript:inverse(this.form);">反选</a> <input type="submit" name="button" id="button" value="删除" />
</label></td>
</tr>
上面这两句红的语句该怎么写写才能像上面的代码一样实现其功能???
<form id="form1" name="form1">
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
<script language="javascript">
function check_all(){
for(var i=0;i<document.form1.elements.length;i++){
var e=document.form1.elements[i];
e.checked=true;
}
}
function inverse(){
for(var i=0;i<document.form1.elements.length;i++){
var e=document.form1.elements[i];
e.checked==true?e.checked=false:e.checked=true;
}
}
</script>
<tr>
<td colspan="2"><label>
<a onclick="javascript:check_all();" href="#">全选</a>/
<a href="#" onclick="javascript:inverse();">反选</a>
<input type="submit" name="button" id="button" value="删除" />
</label></td>
</tr>
</form>