解释该段代码为什么不能正确执行,向上滚动

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>制作我的第一个网页</title>
        <style>
        *{margin:0px;padding:0px;}
            #o{border:1px solid;}
        </style>
        <script>
            var e=document.getElementById("p")
            e.scrollTop=90;
        </script>
    </head>
    <body>
        <div id="o">
      <ul id="p">
            <li>第1个</li>
             <li>第2个</li>
              <li>第3个</li>
               <li>第4个</li>
                <li>第5个</li>
                 <li>第6个</li>
                  <li>第7个</li>
                   <li>第8个</li>
                    <li>第9个</li>
                     <li>第10个</li>
        </ul> </div>
    </body>
</html>



油泼裤带面
浏览 1576回答 3
3回答

梦魂清风

<!DOCTYPE HTML> <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">         <title>制作我的第一个网页</title>         <style>         *{margin:0px;padding:0px;}         #o{border:1px solid;  height:100px; overflow-y: scroll; }         </style>         <script src="js/jquery.min.js"></script>         <script>             $(function(){                 $(".btn").click(function(){                     alert($("#o").scrollTop()+"px");                     $("#o").scrollTop(10);                 });             });         </script>     </head>     <body>         <div id="o">           <ul id="p">                 <li>第1个</li>                  <li>第2个</li>                   <li>第3个</li>                    <li>第4个</li>                     <li>第5个</li>                      <li>第6个</li>                       <li>第7个</li>                        <li>第8个</li>                         <li>第9个</li>                  <li>第10个</li>             </ul>         </div>         <button class="btn"> 点击滚动 </button>      </body> </html>没有向上滚动的原因:1、scrollTop() 方法是属于jquery框架的 ,你没有 导包。2、ul #p 没有 滚动条 ,方法不会生效。3、scrollTop(10) 参数写在括号里面,用于定位滚动条位置的。(纯手打,求采纳 梦魂清风 @author:dream breeze); 已经上代码(已测试,温馨提示请导包)。

大写的王

js部分放到下面去执行,放上面你可以F12看下对象是报错的null,没有获取到 <!DOCTYPE HTML> <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">         <title>制作我的第一个网页</title>         <style>         *{margin:0px;padding:0px;}             #o{border:1px solid;}         </style>              </head>     <body>                  <div id="o">           <ul id="p">                 <li>第1个</li>                  <li>第2个</li>                   <li>第3个</li>                    <li>第4个</li>                     <li>第5个</li>                      <li>第6个</li>                       <li>第7个</li>                        <li>第8个</li>                         <li>第9个</li>                          <li>第10个</li>             </ul>          </div>         <script>             var e=document.getElementById("p")             e.scrollTop=90;         </script>     </body> </html>

慕的地8582982

ENJEUXHDMPELLHKTPRAPZOJSHKGWDMISUMOXNXGJGHQTOXMHWZBXAJSAXAKGWLVEBLYTPLORNDFCLWYAJFHXGAXGRBJAXTCLAQABDNENKGCKVXBKTCSCEHWXHEUJMCTITPSPCLIRPTCSUXAOQTEHEZVXUEWFOEUXZPTCYIXUHBLSTPJYRPCCDAMVQKDhttps://www.imooc.com/wenda/detail/362338ECCXELIYGOCWRTNOTDBJXVUOLPCAURAVMIBLPIPMMDHBCOFMKULNYBZHHSWQKKBIWTPCVWMJDUVPDGHKRMJUEUYXCQEFMABOXBYSRYIBGOSMJRQGPIPPMCWTJQCUHLVUKGKKRGJJPSIYEROEFOPZYOCISEERHAVRIFKENLNALMNRRREULKLLYCCJCSWXXGEOPSLYPCOHVOTAUKNBMLXDHAQNTXABUQKDQFLUDNKQCOTMCOJYFQHTGTWMQZTLVQAWXXATLLLBSILUEYBPTKUBHDXYSSIRKRPLVOPOHCVSCYYLLFWSPYVYIROHBBOOZXKSEXUOHQGQPTHXAJMDRHRSVDJWGAUWLRBKPIYISBBYKXYZTSTXAPFYLFMCOIMXCQPQQXTJTJDXTJGMWSTEOYLLUBLUTKTBVUUKAOOAOCTVLZVPJDQWZJQKGYJGCFTXXGXXCZMINJDQNEAZTQBGJSCWKUJQGLGGENDHGWJEUQGEUAKWZKHJLGQKXEUUKECPFWOIYULZYNTWCVZCLLVEGZCCYTZZFYBKGJCADMJSYBAHAKKUNEDABBGMWXDQAAKLCRUKUNDTFSCSHXHZJMIYYIYUJXXRRELDGJEOXNIOCBEERNWWWGKNWEEVBVOFYMWCPJESVMWQQJPMJDFFEOOURUPYDLBYUXUQZPSKZDTBEOXTEU
打开App,查看更多内容
随时随地看视频慕课网APP