查看: 749|回复: 1
|
javascript row rollover + checkbox
[复制链接]
|
|
user只要按table的row,那个row的checkbox就会打钩?
我找到的是row rollover。。
我想问,
var cb="cb"+i;
document.editform.cb.checked=true
<html>
<head>
<title>Table Row Rollover Demo</title>
<style type="text/css">
table{ width: 98%; border: 1px solid blue; }
td{ border: 1px solid #DDD; }
.whi { background: #FFF; cursor: default }
.red { background: #F00; cursor: default; }
.black { background: #FEEEEE; cursor: default; }
td a{
background: #F00;
}
</style>
<script>
function f(o,b){ o.className = (b) ? 'red' : 'whi'; } // event handler
function init(){//dynamic event handler assignment
var obj = null;
for(i=0;i<3;i++){ // 0..maxTableRows
obj = document.getElementById("cb"+i); // find the IDs of the table...
obj.onmouseover = function(){f(this,1);
} // assign a onmouseover event handler to each row
obj.onmouseout = function(){f(this,0);} // assign a onmouseout event handler to each row
}
}
</script>
</head>
<body onLoad="init();">
<form name="editform" method="post" action="">
<table align="center">
<tr id="cb0">
<td><input type="checkbox" name="cb0"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr id="cb1">
<td><input type="checkbox" name="cb1"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr id="cb2">
<td><input type="checkbox" name="cb2"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<br>
<br>
<br>
</form>
</body>
</html> |
|
|
|
|
|
|
|
发表于 5-4-2006 12:20 AM
|
显示全部楼层
- <html>
- <head>
- <style>
- #tbl { cursor: hand }
- </style>
- <script>
- function check(obj)
- {
- if (event.srcElement.type != "checkbox")
- {
- v = obj.getElementsByTagName("input");
- v[0].checked = !v[0].checked;
- }
- }
- function init()
- {
- for (var i = 0; i < tbl.rows.length; i++)
- {
- tbl.rows[i].onclick = function () { check(this) };
- }
- }
- </script>
- </head>
- <body onload="init()">
- <form name="frm1">
- <table border="1" id="tbl">
- <tr>
- <td><input type="checkbox" name="cb1" /></td>
- <td>Description A1</td>
- <td>Description A2</td>
- </tr>
- <tr>
- <td><input type="checkbox" name="cb2" /></td>
- <td>Description B1</td>
- <td>Description B2</td>
- </tr>
- </table>
- </form>
- </body>
复制代码
不过,只能在 Internet Explorer 跑。
唉,不 portable,一点用都没有了。嘻嘻。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|