发新话题
打印

OnMouseOver时使所在行高亮

OnMouseOver时使所在行高亮

在数据显示时,OnMouseOver引起行颜色变化。
(一般做法)
引用:
<tr onMouseOver="this.style.backgroundColor='#ebf7fe';" onMouseOut="this.style.backgroundColor='#fbfbfb';">
<td>World</td>
<td>World</td>
<td>World</td>
<td><a href="/pp/phplink/admin/categories.php?a=edit&category_id=36">Edit</a></td>
<td><a href="/pp/phplink/admin/categories.php?a=delete&category_id=36">Delete</a></td>
</tr>

TOP

采用javascript简单变色

表格如下:
复制内容到剪贴板
代码:
<table width="500" align="center" style="border:1px #f0f0f0 solid">
<tbody id="lst">
        <tr>
        <td><input name="t1" id="t1" type="checkbox" value="0" /></td>
        <td>World</td>
        <td>World</td>
        <td><a href="#">Edit</a></td>
        <td><a href="#">Delete</a></td>
        </tr>
</tbody>
</table>
CSS如下:
复制内容到剪贴板
代码:
<style type="text/css">
    /* <![CDATA[ */
    html {
        overflow-y: scroll;
    }
/*除IE的浏览器下直接用:hover即可*/
#lst tr:hover, .nor{ background:#ccc;}
.unor{ background:#00FF00;}
.marked{background:#0099FF;}
    /* ]]> */
    </style>
使用JavaScript变颜色
代码:
复制内容到剪贴板
代码:
<script language="javascript">
// <![CDATA[
function mydo()
{
var el = document.getElementById('lst');
var items = el.getElementsByTagName('tr');
for(var i=0; i < items.length; i++){
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
                items[i].onmouseover = function() {
                        this.className += ' nor';
                }
                items[i].onmouseout = function() {
                        this.className = this.className.replace( ' nor', '' );
                }
           }
  }
}
window.onload = mydo;
// ]]>

TOP

使用prototype修改上面js代码

复制内容到剪贴板
代码:
// u must include prototype :)

function mydo()
{
        var el = $('lst').getElementsByTagName('tr')
        var nodes = $A(el);
        nodes.each(function(node){
                node.onmouseover = function (){
                        this.className += ' unor';
                }
                node.onmouseout = function() {
            this.className = this.className.replace( ' unor', '' );
        }
        });
}

TOP

加强版本,增加checkbox选项。

参考自phpmyadmin
复制内容到剪贴板
代码:
var marked_row = new Array;
function PMA_markRowsInit() {
    // for every table row ...
        var el = document.getElementById('lst');
    var rows = el.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class '' or 'even' ...
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }

        // ... and disable label ...
        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}

TOP

可测试的附件

可测试的附件
附件: 您所在的用户组无法下载或查看附件

TOP

票18

支持!!呵呵  
  











上海到哥德堡机票
择程机票提供全球航线机票,专业申请国际紧张机位及复杂航线机票。上海到哥德堡机票有最新特价,有需要订购上海到哥德堡机票的朋友请尽快来电问询!
上海到奥斯陆机票
择程机票提供全球航线机票,专业申请国际紧张机位及复杂航线机票。上海到奥斯陆机票有最新特价,有需要订购上海到奥斯陆机票的朋友请尽快来电问询!
上海到塔林机票
择程机票提供全球航线机票,专业申请国际紧张机位及复杂航线机票。上海到塔林机票有最新特价,有需要订购上海到塔林机票的朋友请尽快来电问询!
上海到华沙机票
择程机票提供全球航线机票,专业申请国际紧张机位及复杂航线机票。上海到华沙机票有最新特价,有需要订购上海到华沙机票的朋友请尽快来电问询!
上海到克拉科夫机票
择程机票提供全球航线机票,专业申请国际紧张机位及复杂航线机票。上海到克拉科夫机票有最新特价,有需要订购上海到克拉科夫机票的朋友请尽快来电问询!

TOP

万用表

勇敢与持枪劫匪搏斗 巴西华侨拼死保住赈灾捐款





















名牌制造万用表、电容表、钳形表、兆欧表、功率表、电桥、电流表、相序表、钳形功率表、谐波分析仪、红外测温仪、电容、风速仪噪音计、中英文电子线号机等

TOP