多个checkbox,只要选中,那个单元格的底色就发生变化. <td >标题文字:<input name="fb" type="checkbox" value="" id =check<%= i %> onclick="this.parentNode.backGroundColor='yellow'"></td> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 改下<input name="fb" type="checkbox" value="" id ="check" onclick="this.parentNode.style.backgroundColor='yellow'"> 感谢.这一步是可以做到点击就变色.但有个问题:因为有些checkbox我要预先选中,那么页面执行后,不管是选中的还是没选中的,底色都是白色.可不可以根据选中与否来确定底色?<input name="fb" type="checkbox" value="" id ="check" onclick="this.parentNode.style.backgroundColor='yellow'" <% if right(rs("mc"),1)=1 then reponse.write "checked" %>> <script language="JavaScript" type="text/JavaScript">function ch(is){if(is.checked==true){ is.parentNode.style.backgroundColor='yellow';}else{ is.parentNode.style.backgroundColor='';}}</script><table> <tr> <td><input name="checkbox1" type="checkbox" id="checkbox1" value="checkbox" onClick="ch(this)"></td> <td><input type="checkbox" name="checkbox" value="checkbox" onClick="ch(this)"></td> </tr></table> function fun(){ var a=document.getElementsByTagName("input"); for(var i=0;i<a.length;i++){ if(a[i].type=='checkbox'){ if(a[i].checked==true){ a[i].parentNode.style.backgroundColor='yellow'; } } }} 谢谢.经测试,选中为黄色,不选中为白色已可达到目标.但是页面刚打开的时候checkbox为选中的情况下底色还是白色的.有没有好办法在页面初始的时候做一次判断?俺只学过VB,对JAVA是一点不知. function init(){//do somthing}<body onload="init()">这个方法在页面load的时候会做的 <body onload="fun()">function fun(){ var a=document.getElementsByTagName("input"); for(var i=0;i<a.length;i++){ if(a[i].type=='checkbox'){ if(a[i].checked==true){ a[i].parentNode.style.backgroundColor='yellow'; } } }} mingxuan3000(铭轩) 的方法可行.THANKS.结贴. [分享]6个JS小游戏代码 求正则批量替换 如何实现循环动态添加。 js 类变量定义 鼠标移入 移出 显示与隐藏层的问题? jQuery 事件冒泡 帮忙给出判断是否是日期和数字的函数 请教 最后一个li的效果不需要实现 请教各位大神一个问题,请进来看 请问如何在ASP。NET中使用MzTreeView呢?高手毕看的问题哦。。梅子大虾帮忙啊。。。 一个页面中放置多个同样的JS组件,如何避免冲突?HTC编程就能避免吗?
<input name="fb" type="checkbox" value="" id ="check" onclick="this.parentNode.style.backgroundColor='yellow'">
因为有些checkbox我要预先选中,那么页面执行后,不管是选中的还是没选中的,底色都是白色.
可不可以根据选中与否来确定底色?
<input name="fb" type="checkbox" value="" id ="check" onclick="this.parentNode.style.backgroundColor='yellow'" <% if right(rs("mc"),1)=1 then reponse.write "checked" %>>
function ch(is)
{
if(is.checked==true)
{
is.parentNode.style.backgroundColor='yellow';
}
else
{
is.parentNode.style.backgroundColor='';
}
}
</script><table>
<tr>
<td><input name="checkbox1" type="checkbox" id="checkbox1" value="checkbox" onClick="ch(this)"></td>
<td><input type="checkbox" name="checkbox" value="checkbox" onClick="ch(this)"></td>
</tr></table>
var a=document.getElementsByTagName("input");
for(var i=0;i<a.length;i++){
if(a[i].type=='checkbox'){
if(a[i].checked==true){
a[i].parentNode.style.backgroundColor='yellow';
}
}
}
}
经测试,选中为黄色,不选中为白色已可达到目标.
但是页面刚打开的时候checkbox为选中的情况下底色还是白色的.
有没有好办法在页面初始的时候做一次判断?俺只学过VB,对JAVA是一点不知.
{
//do somthing
}
<body onload="init()">
这个方法在页面load的时候会做的
var a=document.getElementsByTagName("input");
for(var i=0;i<a.length;i++){
if(a[i].type=='checkbox'){
if(a[i].checked==true){
a[i].parentNode.style.backgroundColor='yellow';
}
}
}
}
THANKS.
结贴.