開發中常用的js命令

2022-08-09 15:27:13 字數 1882 閱讀 1420

1、獲得視窗長寬高

$(window).width();//瀏覽器當前視窗可視區域寬度

$(document).width();//瀏覽器視窗文件的寬度

$(document.body).width();//瀏覽器當前視窗body的寬度

2、offset屬性

包含2個屬性:top和left

例子:

hello

2nd paragraph

3、scrolltop()和scrollleft()屬性(注意:如果視窗不滾動或者非常高,那就是0)

doctype html

>

<

html

lang

="en"

>

<

head

>

<

meta

charset

="utf-8"

>

<

title

>scrollleft demo

title

>

<

style

>

p style

>

<

script

src=""

>

script

>

head

>

<

body

>

<

p>hello

p><

p>

p>

<

script

>

varp

=$(

"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)

還有更多筆記會在後續補充!

開發中常用linux命令

1.找出所有shell 裡面,找到所有shell find opt task grep v pyspark2 grep sh a.sh 2.找出含有cluster 字串的檔案 過濾其中有submit 和 cluster 字串的shell檔案 import os with open a.sh r as...

JS開發中常用的小技巧

123 functiongetradomnum min,max 12 34functiongetradomfromarr arr 12 345functiongetarray len 等同於 12 3456 7functiongetarray len console.log arr 12 34var...

開發中常用js記錄(三)

1 jquery 判斷乙個元素下是否有指定的class div is classname div hasclass redcolor 2 獲得視窗長寬等 window height 瀏覽器當前視窗可視區域高度 document height 瀏覽器當前視窗文件的高度 document.body he...