IE Bug
document.getElementsByName
1. 用脚本创建的元素取不到
2. 不区分ID 与 Name
3. 有时候取不到
Html.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
无标题页
</title><link href="css/common.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="js/TabView.js"></script>
</head>
<body>
<form name="form1" method="post" action="TabPage.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE5MjA4NjA2MjFkZD9ffN/jI/2CVbmIS4+/ml3/lLao" />
</div>
<div id="divTabs">
<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
<tr valign="middle">
<td id="TabPageEx5" name="TabPageEx" onclick="showContent(this.id);" class="UltraWebTab1SelT" onmouseover="this.className = 'UltraWebTab1HovT'" onmouseout="mouseOut(this);" unselectable="on">缺陷单<input name="hdTabPageEx5" type="hidden" id="hdTabPageEx5" value="Tab1.aspx" /></td>
<td id="TabPageEx3" name="TabPageEx" onclick="showContent(this.id);" class="UltraWebTab1SelT" onmouseover="this.className = 'UltraWebTab1HovT'" onmouseout="mouseOut(this);" unselectable="on">工单1<input name="hdTabPageEx3" type="hidden" id="hdTabPageEx3" value="WebForm2.aspx" /></td>
<td id="TabPageEx6" name="TabPageEx" onclick="showContent(this.id);" class="UltraWebTab1SelT" onmouseover="this.className = 'UltraWebTab1HovT'" onmouseout="mouseOut(this);" unselectable="on">工单2<input name="hdTabPageEx6" type="hidden" id="hdTabPageEx6" value="WebForm3.aspx" /></td>
<td width="50%" style="height: 26px">
</td>
</tr>
</table>
<table width="100%">
<tr>
<td colspan="2">
<iframe id="iframe" src="Tab1.aspx" frameborder="0" width="100%" scrolling="auto"
height="500"></iframe>
</td>
</tr>
</table>
</div>
</form>
<script type="text/javascript">
showContent();
</script>
</body>
</html>
Js
function showContent(id)
{
if(id==undefined)
{
id=document.getElementsByName("TabPageEx")[0]; 取不到 name 为 TabPageEx 的 元素
}
var myFrame=document.getElementById("iframe");
var url="";
var hdID="hd"+id;
url=document.getElementById(hdID).value;
myFrame.src=url;
setUltraWebTabDefault(id);
}
function setUltraWebTabDefault(id)
{
var tabs=document.getElementsByName("TabPageEx");
for(i=0;i<tabs.length;i++)
{
tabs[i].className="UltraWebTab1DefT";
}
document.getElementById(id).className="UltraWebTab1SelT";
}
function mouseOut(obj)
{
if(obj.className!="UltraWebTab1SelT")
{
this.className='UltraWebTab1DisT';
}
}