在Firefox中使用javascript获取控件属性

时间:2009-03-30 15:16:04

标签: javascript firefox gridview

我正在尝试访问控件的属性,虽然它在IE6中运行良好,但在FF3中,它失败了。我在做:

alert(document.getElementById(gridViewCtlId).style.display);
alert(document.getElementById(gridViewCtlId).style);

第一个显示空白弹出窗口,而第二个显示'undefined'

我做

alert(document.getElementById(gridViewCtlId).id);

我得到了该框的正确ID以及:

alert(document.getElementById(gridViewCtlId));

我在HTML表格中得到了它。

这在IE中完美运行但不是FF。我需要做些什么来实现这项功能?

编辑:gridViewCtlId定义为:

var gridViewCtlId = '<%=GridView.ClientID%>';

以下是完整代码:

var itemVisible= '<%=ItemVisible.ClientID%>';

function onGridViewRowSelected(rowIdx)
{
    alert(document.getElementById(gridViewCtlId).style.display);
    alert(document.getElementById(gridViewCtlId).style);
    if (document.getElementById(gridViewCtlId).disabled == false)
    {
        alert("hi1");
        var selRowCCA = getSelectedRow(rowIdx);
        if (curSelRow != null)
        {   
            alert("hi2");
            var previousRow = getSelectedRow(previousRowIndx);

            var CountIdx = previousRowIndx % 2;
            if (document.getElementById(itemVisible) == null)
            {
                if (CountIdx == 0)
                {
                    alert("hi");
                    previousRow.style.backgroundColor = 'Silver';
                }
                else
                {
                    previousRow.style.backgroundColor = 'White';
                }
            }
        }

        if (null != selRow)
        {
            alert("new");
            previousRowIndx = rowIdx;
            curSelRow = selRow;
            selRow.style.backgroundColor = 'Red';
        }
    }
}

它几乎是一个onClick,我必须调用该函数将其恢复为原始颜色(使用交替的颜色行)。 IE,这很好用。如果我做第一个警报

alert(document.getElementById(gridViewCtlId).disabled);

我会得到真或假。 这样的原因是因为有人要在文本框中输入内容,而第一个gridview将根据textbox中的内容填充。然后,当某人在第一个gridview中选择了某些内容时,gridview将被禁用,然后填充一秒。所以我在检查gridview的禁用部分时遇到了问题。

1 个答案:

答案 0 :(得分:0)

<div id="test">
</div>
<script type="text/javascript">
var gridViewCtlIdCCA = 'test';
alert(document.getElementById(gridViewCtlIdCCA).style);
</script>

在Firefox 2和3中提醒[object CSSStyleDefintion]

如果.style未定义,.style.display会产生错误,则不会提醒空对话框(除非您正在捕获window.onerror)。

您可以创建一个演示此问题的SSCCE吗?有关SSCCE的更多信息here