第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

jQuery中$this和$的區(qū)別介紹

jQuery中$this和$的區(qū)別介紹

桃花長(zhǎng)相依 2018-11-27 01:00:55
jQuery中$this和$的區(qū)別介紹
查看完整描述

1 回答

?
人到中年有點(diǎn)甜

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊

$ 是JQuery對(duì)象,是JQuery 常用的一個(gè)回傳函數(shù),定義為 "選取" 英文是 selector 的縮寫例子︰$.function();就是 選取 JQuery 定義的 function() 執(zhí)行$('input')就是 選取 HTML 當(dāng)中全部的 input 標(biāo)簽$('#abc')就是 選取 HTML 當(dāng)中 ID 名稱為 abc 的物件$.fn.testing = function() {}就是 選取 JQuery 內(nèi)核函數(shù) fn (函數(shù)) 回傳給 testing 這個(gè)名稱、定義為一個(gè)功能 function()

$this 只是個(gè)變量名,加$是為說(shuō)明其是個(gè)jquery對(duì)象

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

// this其實(shí)是一個(gè)Html 元素。

// $this 只是個(gè)變量名,加$是為說(shuō)明其是個(gè)jquery對(duì)象。

// 而$(this)是個(gè)轉(zhuǎn)換,將this表示的dom對(duì)象轉(zhuǎn)為jquery對(duì)象,這樣就可以使用jquery提供的方法操作。

(function($){

    $.fn.hilight = function(options){

        debug(this); 

        var defaults = {

            foreground: 'red',

            background: 'yellow'

        }; 

        var opts = $.extend({}, $.fn.hilight.defaults, options); 

        return this.each(function() {

      // this其實(shí)是一個(gè)Html 元素。

      // $this 只是個(gè)變量名,加$是為說(shuō)明其是個(gè)jquery對(duì)象。

      // 而$(this)是個(gè)轉(zhuǎn)換,將this表示的dom對(duì)象轉(zhuǎn)為jquery對(duì)象,這樣就可以使用jquery提供的方法操作。

            $this = $(this); 

            // build element specific options

            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;             

            // update element styles

            $this.css({

                backgroundColor: o.background,

                color: o.foreground

            }); 

            var markup = $this.html();

            // call our format function 

            markup = $.fn.hilight.format(markup); 

            $this.html(markup);

        }); 

    }; 

    // define our format function

    $.fn.hilight.format = function(txt) {

        return '<strong>' + txt + '</strong>';

    }; 

    // 插件的defaults

    $.fn.hilight.defaults = {

        foreground: 'red',

        background: 'yellow'

    }; 

    function debug($obj) {

        if (window.console && window.console.log){

            window.console.log('hilight selection count: ' + $obj.size());

        }

    }; 

})(jQuery)


 


查看完整回答
反對(duì) 回復(fù) 2018-12-23
  • 1 回答
  • 0 關(guān)注
  • 473 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)