开发者

Question about javascript document.forms for ID and name attribute in HTML forms in some IE8 Browser

We have a old J2EE struts application which only has ID in the form, and uses document.forms("theName") to get the form object in the javascript. The html page is XHTML.

It seems works OK in firefox and in most of the IE8 browser, but开发者_运维技巧 it fails in some other IE 8 brwosers. The version and subversion of the IE browsers which works and not works could be exactly the same.

We hope to find some IE8 patch to solve the problem without changing the J2EE code/page.

Any suggestion? Thanks.

Here is the testing page, when you click on "Call on button1", the popup works fine in most of the IE8 browser, but failed in some IE8, especially those newly installed IE8.

<html>
<head>
<script language="JavaScript">
function clickFirstButton()
{
document.forms["myForm"].button1.click();
}
</script>
</head>
<body>
<form id="myForm">
  <input type="button"
         value="Display alert box"
         id="button1"
         onClick="alert('You clicked the first button11.')"><br>

  <input type="button"
         value="Call on button 1"
         id="button2"
         onClick="javascript:clickFirstButton()">
</form>    
</body>
</html>


document.forms uses NAME
change to document.getElementById("myForm") or give the form a name too

Also remove the javascript: which is only needed if there is a VBScript as the very first script on the page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜