Javascript表选择 [英] Javascript Table Select

查看:46
本文介绍了Javascript表选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择一个表格行,并使用Javascript突出显示它.但是,似乎没有任何效果.当我注释掉以下代码的前两行时,可以突出显示,但是当我单击另一行时,先前选择的行将保持突出显示,而不是回到白色.

I am trying to select a table row, and highlight it with Javascript. However, nothing seems to work. When I comment out the first two lines of the following code, I can highlight, but when I click another row, the previously selected rows stay highlighted instead of going back to white.

    var selectedEventId = 0;

    function SelectRow(tableRow){
       var SelectedRow = Document.getElementById('selectedEventId');
       SelectedRow.style.backgroundColor = 'white';

       var frame = document.getElementById('additionalText');
       frame.src="iframeContents.php?id="+tableRow.id;
       selectedEventId = tableRow.id;
       tableRow.style.backgroundColor = '3366ff';
       var prevRow = document.getElementById('selectedEventId');
       return;

    }//end SelectRow

任何帮助将不胜感激.

推荐答案

尝试一下:


var selectedEventId = 0; 
var prevRow = ''; 
function SelectRow(tableRow){ 
    if (prevRow != '') { prevRow.backgroundColor = 'white'; }
    var frame = document.getElementById('additionalText'); 
    frame.src="iframeContents.php?id="+tableRow.id; 
    selectedEventId = tableRow.id; 
    tableRow.style.backgroundColor = '3366ff';
    // based on the assumption that selectedEventId is set as a global variable
    prevRow = document.getElementById(selectedEventId);
    return; 
}

这篇关于Javascript表选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆