js 簡易封裝jquery

2021-10-06 04:43:28 字數 2961 閱讀 1486

(一).引入『$』符號

html:

"myjq.js"

>

<

/script>

<

/body>

js:

;

//防止受到別的js檔案影響

(function()

; window.jquery = jquery;

window.$ = window.jquery;

console.

log($(

));}

)();

(二).dom節點的選取

比如我們要完成(xx

x).c

ss()

,這個j

q語句,

我們可以

當作物件

.方法但

是要完成

(***).css(),這個jq語句,我們可以當作物件.方法 但是要完成

(xxx).

css(

),這個

jq語句

,我們可

以當作對

象.方法

但是要完

成(***).css().background(),物件.方法.方法是不可以的,會報錯。

我們需要obj.a()*****>返回物件 .b()必須這樣做,我們首先要有這種思想

console.

log($(

'li'))

;<

/script>

;

(function()

;var

markarray

=function

(arr,that)

brr.length=arr.length;

return brr;};

jquery.prototype =

, a:

function()

, b:

function()

, c:

function()

};jquery.prototype.init.prototype= jquery.prototype;

window.jquery = window.$ = jquery;})

();

(三).dom新增方法:

js:

;

(function()

;var

markarray

=function

(arr, that)

brr.length = arr.length;

return brr;};

jquery.prototype =

else

return

markarray

(dom,

this);

//返回乙個物件},

hover:

function

(over, out)

, css:

function

(attr, val)

return

this;}

, html:

function

(val)

return

this;}

, first:

function()

, last:

function()

, eq:

function

(num)};

jquery.prototype.init.prototype = jquery.prototype;

window.jquery = window.$ = jquery;})

();

html:

<

!doctype html>

"en"

>

"utf-8"

>

title<

/title>

<

/head>

#box

<

/style>

"box"

>

111111111

<

/div>

1<

/li>

2<

/li>

3<

/li>

4<

/li>

5<

/li>

<

/ul>

"myjq.js"

>

<

/script>

$("#box").

hover

(function()

,function()

)$("#box").

css(

"background"

,"red");

$("ul li").

first()

.css

("background"

,"red");

$("ul li").

last()

.css

("background"

,"red");

$("ul li").

eq(2)

.css

("background"

,"blue");

<

/script>

<

/body>

<

/html>

Js之AJAX簡易封裝

提供對原生ajax的簡易封裝 封裝ajax庫 author wenqian email 843462167 qq.com function 提供path query選項 getparamswhere query 傳送請求 url 請求位址 method 請求方式 params 引數 headers ...

cookie方法封裝(JS及jQUery)

js封裝好cookie方法 function addcookie key value day path domain else function getcookie key 預設情況下只能刪除預設路徑中儲存的cookie,如果想刪除指定路徑儲存的cookie,那麼必須在刪除的時候指定路徑才可以 fu...

JS和JQUERY常見函式封裝方式

js中常用的封裝函式4種方法 1.函式封裝法 function box 2.封裝成物件 let cookie set 3.封裝成建構函式 function dog 4.類的方法 class person show jquery中常見的封裝函式方法 方法一 extend 方法二 fn.mytest f...