(1)使用google提供的jQuery,加載時間少了,給用戶帶來好的用戶體驗,而且減少了服務器的流量
<script
type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
(2)判斷對象是否定義或爲空,是否等於某一值
if (s == "undefined" || s == null)
s == "xml" , 三個等號 === 表示類型和值都必須相等。
(3)判斷string長度
使用str.length
(4)數組使用,同樣可以使用length判斷數組長度
var users = [];
var userA = [];
userA.name = "Sam";
userA.age = 26;
users.push(userA);
var userB = [];
userB.name = "Jim";
userB.age = 27;
users.push(userB);
for(i in users){
alert(users[i].name + users[i].age);
}
(5)jquery html方法
<div id="divHtml"> this is div</div>
a. 替換value爲test
$(document).ready(function(){
$("#divHtml").html("test");
});
b.清空value
$("#divHtml").html("");
c.追加新內容
$("#divHtml").append(" new line");
(6)顯示隱藏某一元素
$("#divHtml").show(); $("#divHtml").css("display","block");
$("#divHtml").hide(); $("#divHtml").css("display","none");
(7)取消onclick或重新綁定
$('#btndemo').removeAttr('onclick').unbind('click').click(function(){
toPage(1);
})