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......餘下全文>>