怎么才能onMouseOver,onMouseOut,onMousedown时tr背景各是一种? <tr onMouseOver="this.bgColor='red'" onMouseOut="this.bgColor='blue'" ... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 孟子E章大大,是的就是这种,不过关键是最后一点我没弄好。不会。就是当onMousedown时的状态。跟163.com邮局一样的一个选定状态时,input为选定。。再次input就取消,,背景色也回复到原来状态 <input type="checkbox" name="elements" id=="elements">如果才能是点一次选定,再点一次就取消了??<tr onMousedown="func1()" ></tr>function func1(){ var a=document.getElementById("elements"); if(a.checked == true){ a.checked=false; }else{ a.checked=true; }} 汗,没说清。。有多个一样的<input type="checkbox" name="elements" id="elements">不是只有一行。有很多行的 有很多行就遍历:<script> function change(){ var obj = document.getElementsByName("elements")[0]; if(obj.checked){ color.bgColor = "#FFFFFF"; }else{ //不作操作 }}</script><table border='1'><tr id="color" onMouseOver="this.bgColor='red'" onMouseOut="this.bgColor='blue'" onMousedown="this.bgColor='yellow'"> <td>111111111</td><td><input type="checkbox" name="elements" onclick="change()"></td></tr></table> function func1(){ var a=document.getElementsByName("elements"); for(i=0;i<a.length;i++){ if(a[i].checked == true){ a[i].checked=false; }else{ a[i].checked=true; } }} DeluxWorld(曾经的你)你这样是可行,不过还少了点,背景色选定后不是选定的颜色 mingxuan3000(铭轩) 可怎么才能知道我当前点选的哪个是哪一行啊。要不所有的都会变更了 当前点选的哪个是哪一行? if(a[i].checked == true){ a[i].checked=false; } function func1(){ var a=document.getElementsByName("elements"); for(i=0;i<a.length;i++){ if(a[i].checked == true){ a[i].checked=false; } }} 我把代码贴出来帮我看看好不,,我总弄不好了<script type="text/javascript">var old_bg="";function inStyle(obj){ if(old_bg!="#FF0099") { old_bg=obj.style.background; obj.style.background="#FFFF99";}}function DownStyle(obj){ var e=document.getElementsByName("elements[]"); for(i=0;i<e.length;i++){ if(e[i].checked == true) {obj.style.background="#FF0099";old_bg="#FF0099";} else {obj.style.background=old_bg; } } }function outStyle(obj){obj.style.background=old_bg;}</script><table><tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee"> <td>111111111</td><td><input type="checkbox" name="elements"></td><td>111111111</td><td><input type="checkbox" name="elements"></td><td>111111111</td><td><input type="checkbox" name="elements"></td></tr></table> 你说的是不是这样:<script type="text/javascript">var old_bg="";function inStyle(obj){ if(old_bg!="#FF0099") { old_bg=obj.style.background; obj.style.background="#FFFF99";}}function DownStyle(obj){ var e=document.getElementsByName("elements"); for(i=0;i<e.length;i++){ if(e[i].checked) { obj.style.background="#FF0099"; //old_bg="#FF0099"; break; } else {obj.style.background=old_bg; } } }function outStyle(obj){obj.style.background=old_bg;}</script><table><tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee"> <td>111111111</td><td><input type="checkbox" name="elements"></td><td>111111111</td><td><input type="checkbox" name="elements"></td><td>111111111</td><td><input type="checkbox" name="elements"></td></tr></table> 是这样不?<table id="ice"><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr></table><script type="text/javascript">var overBG = "#FFFF99";var outBG = "#FFFFFF";var selBG = "#FF0099";var tbl = document.getElementById("ice");var chk = document.getElementsByName( "elements[]");for(i=0;i<tbl.rows.length;i++){ tbl.rows[i].onmouseover = function(){ this.style.background = overBG; } tbl.rows[i].onmouseout = function(){ var check = this.cells[1].childNodes[0]; this.style.background = check.checked == true ? selBG : outBG; } tbl.rows[i].onclick = function(){ var check = this.cells[1].childNodes[0]; this.style.background = check.checked == true ? selBG : overBG; }}</script> 才看到回复,那是这样了<table id="ice" style="cursor:default"><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr></table><script type="text/javascript">var overBG = "#999";var outBG = "#FFF";var selBG = "#DDD";var tbl = document.getElementById("ice");var chk = document.getElementsByName( "elements[]");for(i=0;i<tbl.rows.length;i++){ tbl.rows[i].onmouseover = function(){ this.style.background = overBG; } tbl.rows[i].onmouseout = function(){ var check = this.cells[1].childNodes[0]; this.style.background = check.checked == true ? selBG : outBG; } tbl.rows[i].onclick = function(){ var check = this.cells[1].childNodes[0]; check.checked = !check.checked; this.style.background = check.checked == true ? selBG : overBG; }}</script> 我改过了。。你看下效果<script type="text/javascript">var old_bg="";function inStyle(obj){ old_bg=obj.style.background; if(old_bg=="#ff0099") obj.style.background="#FF0099"; else obj.style.background="#FFFF99";}function DownStyle(obj){ var bgtrue=true; //var e=document.getElementsByName("elements[]"); //e.checked=(e.checked?false:true); if(bgtrue) { if(obj.style.background=="#ff0099") {obj.style.background=""; old_bg="";} else {obj.style.background="#FF0099";old_bg="#FF0099";bgtrue=false; } } else {obj.style.background=old_bg; } }function outStyle(obj){obj.style.background=old_bg;}</script><table style="background:#eeeeee"> <tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee"> <td>111111111</td><td><input type="checkbox" name="elements"></td></tr><tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee"><td>111111111</td><td><input type="checkbox" name="elements"></td></tr><tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee"><td>111111111</td><td><input type="checkbox" name="elements"></td></tr></table>但我还要实现点行中任何位置多选框的选定与否也要相关 又改了一下,修改了点击checkbox不能改变状态的BUG<table id="ice" style="cursor:default"><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr><tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr></table><script type="text/javascript">var overBG = "#999";var outBG = "#FFF";var selBG = "#DDD";var tbl = document.getElementById("ice");var chk = document.getElementsByName( "elements[]");for(i=0;i<tbl.rows.length;i++){ tbl.rows[i].onmouseover = function(){ this.style.background = overBG; } tbl.rows[i].onmouseout = function(){ var check = this.cells[1].childNodes[0]; this.style.background = check.checked == true ? selBG : outBG; } tbl.rows[i].onclick = function(e){ var check = this.cells[1].childNodes[0]; e = window.event || e; target = e.srcElement || e.target; if( target != check ) check.checked = !check.checked; this.style.background = check.checked == true ? selBG : overBG; }}</script> ice_berg16(寻梦的稻草人)YES是这种效果。。我试下完了就结贴 jquery 支持安卓等手机web开发不? 想做一个图片的值班表,五天一个循环,循环已经写好,就是调用图片的问题! 如何捕获IFrame中的鼠标数据【高分,不够再加】 那个js charts 组件比较好?开源的 点击弹出层加载网页的问题 如何根据分辨率动态调整margin-left的值? js 滚动图片点击在另一页显示! prompt怎么样得到象select那样的下拉效果? 帮忙看看,谢谢 js给asp.net页面控件赋值 抽空找资料做了XMLHttp的帮助文档,要的兄弟快下啊! 请教如何实现table中background的变幻
关键是最后一点我没弄好。不会。
就是当onMousedown时的状态。
跟163.com邮局一样的一个选定状态时,input为选定。。再次input就取消,,背景色也回复到原来状态
var a=document.getElementById("elements");
if(a.checked == true){
a.checked=false; }else{
a.checked=true; }
}
<input type="checkbox" name="elements" id="elements">
不是只有一行。有很多行的
<script>
function change(){
var obj = document.getElementsByName("elements")[0];
if(obj.checked){
color.bgColor = "#FFFFFF";
}else{
//不作操作
}}
</script>
<table border='1'>
<tr id="color" onMouseOver="this.bgColor='red'" onMouseOut="this.bgColor='blue'" onMousedown="this.bgColor='yellow'">
<td>111111111</td><td><input type="checkbox" name="elements" onclick="change()"></td>
</tr>
</table>
var a=document.getElementsByName("elements");
for(i=0;i<a.length;i++){
if(a[i].checked == true){
a[i].checked=false; }else{
a[i].checked=true; }
}
}
if(a[i].checked == true){
a[i].checked=false; }
var a=document.getElementsByName("elements");
for(i=0;i<a.length;i++){
if(a[i].checked == true){
a[i].checked=false; }
}
}
<script type="text/javascript">
var old_bg="";
function inStyle(obj){
if(old_bg!="#FF0099")
{ old_bg=obj.style.background;
obj.style.background="#FFFF99";}}
function DownStyle(obj){
var e=document.getElementsByName("elements[]");
for(i=0;i<e.length;i++){
if(e[i].checked == true)
{obj.style.background="#FF0099";old_bg="#FF0099";}
else
{obj.style.background=old_bg;
}
}
}
function outStyle(obj){
obj.style.background=old_bg;}</script><table>
<tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee">
<td>111111111</td><td><input type="checkbox" name="elements"></td>
<td>111111111</td><td><input type="checkbox" name="elements"></td>
<td>111111111</td><td><input type="checkbox" name="elements"></td>
</tr>
</table>
<script type="text/javascript">
var old_bg="";
function inStyle(obj){
if(old_bg!="#FF0099")
{ old_bg=obj.style.background;
obj.style.background="#FFFF99";}}
function DownStyle(obj){
var e=document.getElementsByName("elements");
for(i=0;i<e.length;i++){
if(e[i].checked)
{
obj.style.background="#FF0099";
//old_bg="#FF0099";
break;
}
else
{obj.style.background=old_bg;
}
}
}
function outStyle(obj){
obj.style.background=old_bg;}</script><table>
<tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee">
<td>111111111</td><td><input type="checkbox" name="elements"></td>
<td>111111111</td><td><input type="checkbox" name="elements"></td>
<td>111111111</td><td><input type="checkbox" name="elements"></td>
</tr>
</table>
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
</table>
<script type="text/javascript">
var overBG = "#FFFF99";
var outBG = "#FFFFFF";
var selBG = "#FF0099";var tbl = document.getElementById("ice");
var chk = document.getElementsByName( "elements[]");
for(i=0;i<tbl.rows.length;i++)
{
tbl.rows[i].onmouseover = function(){
this.style.background = overBG;
}
tbl.rows[i].onmouseout = function(){
var check = this.cells[1].childNodes[0];
this.style.background = check.checked == true ? selBG : outBG;
}
tbl.rows[i].onclick = function(){
var check = this.cells[1].childNodes[0];
this.style.background = check.checked == true ? selBG : overBG;
}
}
</script>
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
</table>
<script type="text/javascript">
var overBG = "#999";
var outBG = "#FFF";
var selBG = "#DDD";var tbl = document.getElementById("ice");
var chk = document.getElementsByName( "elements[]");
for(i=0;i<tbl.rows.length;i++)
{
tbl.rows[i].onmouseover = function(){
this.style.background = overBG;
}
tbl.rows[i].onmouseout = function(){
var check = this.cells[1].childNodes[0];
this.style.background = check.checked == true ? selBG : outBG;
}
tbl.rows[i].onclick = function(){
var check = this.cells[1].childNodes[0];
check.checked = !check.checked;
this.style.background = check.checked == true ? selBG : overBG;
}
}
</script>
<script type="text/javascript">
var old_bg="";
function inStyle(obj){
old_bg=obj.style.background;
if(old_bg=="#ff0099")
obj.style.background="#FF0099";
else
obj.style.background="#FFFF99";}
function DownStyle(obj){
var bgtrue=true;
//var e=document.getElementsByName("elements[]");
//e.checked=(e.checked?false:true);
if(bgtrue)
{
if(obj.style.background=="#ff0099")
{obj.style.background="";
old_bg="";}
else
{obj.style.background="#FF0099";old_bg="#FF0099";bgtrue=false;
}
}
else
{obj.style.background=old_bg;
}
}
function outStyle(obj){
obj.style.background=old_bg;}</script>
<table style="background:#eeeeee">
<tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee">
<td>111111111</td><td><input type="checkbox" name="elements"></td></tr>
<tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee"><td>111111111</td><td><input type="checkbox" name="elements"></td></tr>
<tr onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee">
<td>111111111</td><td><input type="checkbox" name="elements"></td>
</tr>
</table>但我还要实现点行中任何位置多选框的选定与否也要相关
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
<tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
</table>
<script type="text/javascript">
var overBG = "#999";
var outBG = "#FFF";
var selBG = "#DDD";var tbl = document.getElementById("ice");
var chk = document.getElementsByName( "elements[]");
for(i=0;i<tbl.rows.length;i++)
{
tbl.rows[i].onmouseover = function(){
this.style.background = overBG;
}
tbl.rows[i].onmouseout = function(){
var check = this.cells[1].childNodes[0];
this.style.background = check.checked == true ? selBG : outBG;
}
tbl.rows[i].onclick = function(e){
var check = this.cells[1].childNodes[0];
e = window.event || e;
target = e.srcElement || e.target;
if( target != check ) check.checked = !check.checked;
this.style.background = check.checked == true ? selBG : overBG;
}
}
</script>
我试下完了就结贴