亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

jQuery.fn是什么意思?

jQuery.fn是什么意思?

HUX布斯 2019-07-02 14:54:48
jQuery.fn是什么意思?是什么fn這里的意思?jQuery.fn.jquery
查看完整描述

3 回答

?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

jQuery.fn定義為jQuery.prototype..從源代碼:

jQuery.fn = jQuery.prototype = {
    // ...}

這意味著jQuery.fn.jquery的別名jQuery.prototype.jquery,它返回當前的jQuery版本。再次從源代碼:

// The current version of jQuery being usedjquery: "@VERSION",


查看完整回答
反對 回復 2019-07-02
?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

fn字面上指的是jQuery。prototype.

這一行代碼在源代碼中:

jQuery.fn = jQuery.prototype = {
 //list of functions available to the jQuery api}

但背后真正的工具fn它可以將您自己的功能連接到jQuery中。記住jQuery將是函數的父作用域,所以this將引用jQuery對象。

$.fn.myExtension = function(){
 var currentjQueryObject = this;
 //work with currentObject
 return this;//you can include this if you would like to support chaining};

這里有一個簡單的例子。讓我說我想做兩個擴展,一個放藍色邊框,把文本涂成藍色,然后我要把它們鏈接起來。

jsFiddle Demo

$.fn.blueBorder = function(){
 this.each(function(){
  $(this).css("border","solid blue 2px");
 });
 return this;};$.fn.blueText = function(){
 this.each(function(){
  $(this).css("color","blue");
 });
 return this;};

現在,您可以對這樣的類使用這些:

$('.blue').blueBorder().blueText();

(我知道這是最好的CSS,例如應用不同的類名,但請記住,這只是一個演示,以顯示概念)

這個答案有一個完整擴展的好例子。


查看完整回答
反對 回復 2019-07-02
  • 3 回答
  • 0 關注
  • 981 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號