displayTag 给行加事件

displayTag  给行加事件 row event
http://jira.codehaus.org/browse/DISPL-92

Here's something you can use while you wait for this feature to be added.
  1. function highlightTableRows(tableId) {   
  2.     var previousClass = null;   
  3.     var table = document.getElementById(tableId);   
  4.     var tbody = table.getElementsByTagName("tbody")[0];   
  5.     var rows = tbody.getElementsByTagName("tr");   
  6.     // add event handlers so rows light up and are clickable   
  7.     for (i=0; i < rows.length; i++) {   
  8.         rows[i].onmouseover = function() { previousClass=this.className;this.className+=' over' };   
  9.         rows[i].onmouseout = function() { this.className=previousClass };   
  10.         rows[i].onclick = function() {   
  11.             var cell = this.getElementsByTagName("td")[0];   
  12.             if (cell.getElementsByTagName("a").length > 0) {   
  13.                 var link = cell.getElementsByTagName("a")[0];   
  14.                 if (link.onclick) {   
  15.                     call = link.getAttributeValue("onclick");   
  16.                     // this will not work for links with onclick handlers that return false   
  17.                     eval(call);   
  18.                 } else {   
  19.                   location.href = link.getAttribute("href");   
  20.                 }   
  21.                 this.style.cursor="wait";   
  22.             }   
  23.         }   
  24.     }   
  25. }  
I put this in a global .js file and then call it after my </display:table> using:

<script type="text/javascript">highlightTableRows("userList");</script>

Where my table has an id:

<display:table id="userList">

===============================================================================

I have done a similar thing as above but expanded on it. You can only highlight one row. We wanted to do that coz we only we wanted to apply some kind of action to that row only.
  1. /**  
  2.  * This JavaScript performs the task of highlighting a row in a displayTag table.  
  3.  * The javascript is called by adding the following line in your JSP page after the  
  4.  * declaration of your display tag  
  5.  * <script type="text/javascript">highlightTableRows("searchResultTO");</script>  
  6.  * An example is as follows:  
  7.  * <html>  
  8.  * <body>  
  9.  * <displaytag:table name="${sessionScope.searchResultList}" id="searchResultTO"/>  
  10.  * <script type="text/javascript">highlightTableRows("searchResultTO");</script>  
  11.  * </body>  
  12.  * </html>  
  13.  */  
  14.   
  15.   
  16.   
  17. /**  
  18.  * This function after the displayTag table has been created adds a onclick event  
  19.  * handler to each row in the table. The onclick event will first reset all rows to  
  20.  * the default background color which is white and then assign the clicked row to the  
  21.  * highlight color which is a light green.  
  22.  */  
  23. function highlightTableRows(tableId) {   
  24.     var previousClass = '';   
  25.     var table = document.getElementById(tableId);   
  26.     var tbody = table.getElementsByTagName("tbody")[0];   
  27.     var rows = tbody.getElementsByTagName("tr");   
  28.     // add event handlers so rows light up and are clickable   
  29.     for (i=0; i < rows.length; i++) {   
  30.         rows[i].onmouseover = function() {   
  31. this.style.cursor="hand";   
  32. };   
  33.   
  34. rows[i].onmouseout = function() {   
  35. this.style.cursor='';   
  36. };   
  37.   
  38.         rows[i].onclick = function() {   
  39. //reset all styles to blank for all rows   
  40. resetStylesAroundRow(this);   
  41. this.style.backgroundColor = "#74BAB7";   
  42.             var cell = this.getElementsByTagName("td")[0];   
  43.             if (cell.getElementsByTagName("a").length > 0) {   
  44.                 var link = cell.getElementsByTagName("a")[0];   
  45.                 if (link.onclick) {   
  46.                     call = link.getAttributeValue("onclick");   
  47.                     // this will not work for links with onclick handlers that return false   
  48.                     eval(call);   
  49.                 } else {   
  50.                   location.href = link.getAttribute("href");   
  51.                 }   
  52.                 this.style.cursor="wait";   
  53.             }   
  54.         };   
  55.     }   
  56. }   
  57.   
  58. /**  
  59.  * Resets the table rows back to the default color.  
  60.  */  
  61. function resetStylesAroundRow(row) {   
  62.     var previousClass = '';   
  63.     var table = row.parentElement.parentElement;   
  64.     var tbody = table.getElementsByTagName("tbody")[0];   
  65.     var rows = tbody.getElementsByTagName("tr");   
  66.     for (i=0; i < rows.length; i++) {   
  67.         rows[i].style.backgroundColor = "white";   
  68.     }   
  69. }  
-----------------------------------------------------------------------------
JavaScript与displayTag标签的合作 -- 操作表头
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值