| 发表于:2007-09-06 17:05:38 楼主 |
写了个javascript函数,实现的功能是点击table中的一个row的任意一部分,其中有checkbox的就会被check或uncheck(相对原先的状态) 函数如下: function pickrow(row){ \tvar cell = row.cells; \tfor(var i=0;i <cell.length;i++){ \t\tvar x = cell.getelementsbytagname( "* "); \t\tif(x.length > 0){ \t\t\tfor(var j=0;j <x.length;j++){ \t\t\t\tif(x[j].type = "checkbox "){ \t\t\t\t\tx[j].checked = !x[j].checked; \t\t\t\t} \t\t\t} \t\t} \t} } =================html======================== <table class= "tblist " border= "1 "> <tr class= "thead "> <td class= "thead " width= "auto "> user_id </td> <td class= "thead " width= "auto "> user_name </td> <td class= "thead " width= "auto "> user_password </td> <td class= "thead " width= "auto "> memo </td> <td class= " " width= "5% "> delete </td> </tr> <tr class= " " onclick= "pickrow(this); " onmouseover= "this.style.backgroundcolor = '#ebebeb ';this.style.cursor= 'pointer '; " onmouseout= "this.style.backgroundcolor = 'white ' "> <td class= " " align= "center " width= "auto "> <a href= "index_detail.php?user_id=1 "> 1 </a> </td> <td class= " " align= "center " width= "auto "> admin </td> <td class= " " align= "center " width= "auto "> *a4b6157319038724e3560894f7f932c8886ebfcf </td> <td class= " " align= "center " width= "auto "> admin </td> <td class= " " align= "center " width= "auto "> <input type= "checkbox " name= "user_id[] " value= "1 "> </td> </tr> </table> ===================html==================== 现在的问题是点击row的其他部分都能实现预定功能,但是点击checkbox时却不起作用了。 我想可能是checkbox在tr中,点击checkbox同样触发了tr的onclick事件,所以两个check的效果抵消了。但是如何能避免这种情况发生呢? |
|
|
|
|