zoukankan      html  css  js  c++  java
  • 开发中常用的js命令

    1、获得窗口长宽高

       $(window).width();//浏览器当前窗口可视区域宽度

      $(document).width();//浏览器窗口文档的宽度

      $(document.body).width();//浏览器当前窗口body的宽度

    2、offset属性

     包含2个属性:top和left

    例子:

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>offset demo</title>
    <style>
    p {
    margin-left: 10px;
    }
    </style>
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>
     
    <p>Hello</p><p>2nd Paragraph</p>
     
    <script>
    var p = $( "p:last" );
    var offset = p.offset();
    p.html( "left: " + offset.left + ", top: " + offset.top );
    </script>
     
    </body>
    </html>
    

      

    3、scrollTop()和scrollLeft()属性(注意:如果窗口不滚动或者非常高,那就是0)
      
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>scrollLeft demo</title>
      <style>
      p {
        margin: 10px;
        padding: 5px;
        border: 2px solid #666;
      }
      </style>
      <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>
     
    <p>Hello</p><p></p>
     
    <script>
    var p = $( "p:first" );
    $( "p:last" ).text( "scrollLeft:" + p.scrollLeft() );
    </script>
     
    </body>
    </html>

    4、split()

        var str="a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a";

       var arr=str.split("/");

       console.log(arr);

       console.log(str.length);

    5、join()

    var arr = new Array(3)
    arr[0] = "George"
    arr[1] = "John"
    arr[2] = "Thomas"
    
    document.write(arr.join("."))
    

    6、substring()

    var str="abcdefg";

    var ob=str.substring(0,5);

    console.log(ob);

    7、replace()

    var str="1996-4-6";

    var ob=str.replace(/-/g,"");

    console.log(ob);

    8、indexOf()(注意:对大小写敏感)

    function IndexDemo(str2){
    var str1 = "BABEBIBOBUBABEBIBOBU"
    var s = str1.indexOf(str2);
    return(s);
    }

    还有更多笔记会在后续补充!

     
       
     
     
  • 相关阅读:
    POJ2976 Dropping tests 01分数规划
    POJ 2728 Desert King 01分数规划,最优比率生成树
    codeforces 675E Trains and Statistic 线段树+贪心统计
    codeforces 675D Tree Construction set
    UVA 11235Frequent values(RMQ)
    FZU 2105Digits Count(线段树 + 成段更新)
    HDU 4006The kth great number(K大数 +小顶堆)
    UVA 624CD(01背包输出 + 输出路径)
    HDU 1796How many integers can you find(容斥原理)
    HDU 1817Necklace of Beads(置换+Polya计数)
  • 原文地址:https://www.cnblogs.com/circleone/p/7136689.html
Copyright © 2011-2022 走看看