简体   繁体   中英

How to use fireevent IE8?

IE6,7,8 this code dose not working

anybody help me.

how can i fix it??

<script type="text/javascript">
function call (event) {
  if (document.createEventObject) {   // IE before version 9
   var mouseclickEvent = document.createEventObject (window.event);
   mouseclickEvent.button = 1;  // left button is down
   document.getElementById("test4").fireEvent ("onclick", mousedownEvent);
  }
}
</script>
<body>
  <button id="test" onmouseover="call (event);">call</button>
  <input id="test3" type="file" onclick="alert(6)"/>
</body>

There're several problems in you code:

  1. event and window.event is redundant (and, I'm not sure though, may cause error);
  2. There's no element with id test4 .

The following code has been tested on IE8 and IE6:

<script>
function call()
{
    if(document.createEventObject)
    {
        var evt=document.createEventObject();
        evt.button=1;
        document.getElementById("test").fireEvent("onclick",evt);
    }
}
</script>
<button type="button" onclick="call();">Fire</button>
<input type="text" id="test" onclick="alert(6);" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM