开发者

How to get element by ID in IE? (Visual Studio 8?)

Using document.GetElementById(thingieID开发者_开发知识库) doesn't seem to work. Can anyone help this DOM newbie?


I'm not sure what you are trying to do with the element, or what the problem is.

Here's an example of using document.GetElementById() in a webpage, in a function that is invoked on the onClick event for a button.

<html>
  <head>
    <title>Example of GetElementById</title>
  </head>
  <body>
    <p id="hello">Hello World</p>
    <input type="button" value="Update" onclick="btn1_Click();"/>
    <script type="text/javascript">
      // <![CDATA[
      function btn1_Click()
      {
          if (document.getElementById('hello')) {
              document.getElementById('hello').innerHTML = 'Hello World - this was inserted using JavaScript at ' + new Date().toString();
          }
      }
    // ]]>
    </script>
  </body>
</html>

You can see this run at:
http://jsbin.com/afaga/2

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜