在firefox中使用javascript获取控件属性
我正在尝试访问控件的属性,尽管它在在firefox中使用javascript获取控件属性,javascript,firefox,gridview,Javascript,Firefox,Gridview,我正在尝试访问控件的属性,尽管它在IE6中工作得很好,但在FF3中,它失败了。我正在做: alert(document.getElementById(gridViewCtlId).style.display); alert(document.getElementById(gridViewCtlId).style); 第一个显示空白弹出窗口,而第二个显示“未定义” 我知道 我得到了盒子的正确ID以及: alert(document.getElementById(gridViewCtlId));
IE6
中工作得很好,但在FF3中,它失败了。我正在做:
alert(document.getElementById(gridViewCtlId).style.display);
alert(document.getElementById(gridViewCtlId).style);
第一个显示空白弹出窗口,而第二个显示“未定义”
我知道
我得到了盒子的正确ID以及:
alert(document.getElementById(gridViewCtlId));
我在一个HTML表格中得到了它
这在IE中非常有效,但在FF中不起作用。我需要做什么才能让它正常工作
编辑:gridViewCtlId定义为:
var gridViewCtlId = '<%=GridView.ClientID%>';
我会得到正确或错误。
之所以是这样,是因为有人要在文本框中输入一些内容,而第一个gridview
将根据textbox
中的内容填充。然后,当有人在第一个gridview中选择某个内容时,gridview
将被禁用,然后填充第二个。因此,我在检查gridview的禁用部分时遇到了一个问题
<div id="test">
</div>
<script type="text/javascript">
var gridViewCtlIdCCA = 'test';
alert(document.getElementById(gridViewCtlIdCCA).style);
</script>
var gridViewCtlIdCCA='test';
警报(document.getElementById(gridViewCtlIdCCA.style);
Firefox 2和3中的警报[object cssstyledefination]
如果.style
未定义,则.style.display
将产生错误,而不会向空对话框发出警报(除非您正在捕获窗口.onerror
)
你能创建一个演示问题的模型吗。有关SSCCE的更多信息可用。在对getElementById的调用中,元素ID周围是否缺少“”,或者这是问题中的输入错误?不是,它在其他地方的定义是:var gridViewCtlId=“”;
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';
}
}
}
alert(document.getElementById(gridViewCtlId).disabled);
<div id="test">
</div>
<script type="text/javascript">
var gridViewCtlIdCCA = 'test';
alert(document.getElementById(gridViewCtlIdCCA).style);
</script>