佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 749|回复: 1

javascript row rollover + checkbox

[复制链接]
发表于 28-3-2006 03:05 PM | 显示全部楼层 |阅读模式
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">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                </tr>
                <tr id="cb1">
                        <td><input type="checkbox" name="cb1">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                </tr>
                <tr id="cb2">
                        <td><input type="checkbox" name="cb2">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                </tr>
        </table>
        <br>
        <br>
        <br>
</form>
</body>
</html>
回复

使用道具 举报


ADVERTISEMENT

发表于 5-4-2006 12:20 AM | 显示全部楼层

  1. <html>

  2. <head>
  3. <style>
  4. #tbl { cursor: hand }
  5. </style>

  6. <script>
  7. function check(obj)
  8. {
  9.    if (event.srcElement.type != "checkbox")
  10.    {
  11.       v = obj.getElementsByTagName("input");
  12.       v[0].checked = !v[0].checked;
  13.    }
  14. }

  15. function init()
  16. {
  17.    for (var i = 0; i < tbl.rows.length; i++)
  18.    {
  19.       tbl.rows[i].onclick = function () { check(this) };
  20.    }
  21. }
  22. </script>
  23. </head>

  24. <body onload="init()">

  25. <form name="frm1">

  26. <table border="1" id="tbl">
  27.    <tr>
  28.       <td><input type="checkbox" name="cb1" /></td>
  29.       <td>Description A1</td>
  30.       <td>Description A2</td>
  31.    </tr>
  32.    <tr>
  33.       <td><input type="checkbox" name="cb2" /></td>
  34.       <td>Description B1</td>
  35.       <td>Description B2</td>
  36.    </tr>
  37. </table>

  38. </form>

  39. </body>
复制代码


不过,只能在 Internet Explorer 跑。
唉,不 portable,一点用都没有了。嘻嘻。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 6-3-2025 02:59 AM , Processed in 0.203147 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表