jquery中 $ 和 jQuery 及 $() 的區別,jquery中區別

來源:互聯網
上載者:User

jquery中 $ 和 jQuery 及 $() 的區別,jquery中區別


        用過jquery的人都知道,jquery有兩種用法,一種是$,還有一種是jQuery,那麼這兩種方式在使用上有什麼區別呢?

        答案是這兩種用法沒什麼區別,只是別名而已,用$要比jQuery簡短一些、方便一些,另外其他的前端架構也都用到$符號,如果想不跟其他架構衝突,建議使用jQuery方式。

        還有種方法就是換一個新的縮寫:

1、調用jquery的noConflict函數

JQuery.noConflict();//讓jquery放棄對$的使用權,交給其他js架構使用
2、聲明新的縮寫

var $j = Jquery 
使用$j 來代替 $ 以防止$命名衝突。
       

        $和$()的區別:

        $可以調用那些不需要操作對象的方法(像java代碼中的靜態方法,不用聲明對象就可以操作),如$.prototype,如果是給某個對象賦值(注意,這裡有操作對象),就需要用$('#abc').val('123')的方式,因為像val()等方法中會用到$(this)去操作當前對象。


jquery裡的$("#") 與 js中的$("#"+) 有什不同

一樣的意思啊。只是content是一個變數的而已。$("#ID")和$("#"+ID)是一樣的。
例如<input id="abc1">
<input id="abc2">
<input id="abc3">

$("#abc1");
for(var a=1;a<4;a++){

$("#abc"+a);
}

差不多就是這樣了。看著理解一下。。
 
jquery中outerHeight()與height()的不同?

幫你搜尋了下:
標準瀏覽器下:
height:高度
innerHeight:高度+補白
outerHeight:高度+補白+邊框,參數為true時:高度+補白+邊框+邊距

html代碼:
<div class="width: 150px;height:20px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結果:
在ie中的結果:17px,37px,41px,61px
在ff中的結果:20px,40px,44px,64px

html代碼:
<div class="width: 150px;height: 41px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結果:
在ie中的結果:17px,37px,41px,61px
在ff中的結果:41px,61px,65px,85px

html代碼:
<div class="width: 150px;height: 42px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結果:
在ie中的結果:18px,38px,42px,62px
在ff中的結果:42px,62px,66px,86px

html代碼:
<div class="width: 150px;height: 60px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.