在IE11中没有调用onScroll事件

onScroll event not getting called in IE11

本文关键字:调用 onScroll 事件 IE11      更新时间:2023-09-26
<html>
    <head>
    <style>
div {`border: 1px solid black;
    width: 200px;
    height: 100px;
    overflow: scroll;`
    }
    </style>
    </head>
    <body>
    <p>Try the scrollbar in div.</p>
    <div id="xyz">In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since.</div>
    <p>Scrolled <span id="demo">0</span> times.</p>
    <script>
    document.getElementById("xyz").onscroll = myFnction;
    var x = 0;
    function myFnction() {
        document.getElementById("demo").innerHTML = x += 1;
    }
    </script>
    </body>
    </html>

我也尝试过在div标签内的onscroll事件,但它也不起作用。如果有人有解决办法,请回复。

css中有什么错别字吗??

试试这个CSS:

div {
     border: 1px solid black;
     width: 200px;
     height: 100px;
     overflow: scroll;
  }
http://jsfiddle.net/nksnk89z/