1.ajax的學(xué)習(xí)
HTML5中的ajax相當(dāng)于iOS中的afnetworking;詳見jQuery ajax - ajax() 方法;
對(duì)ajax使用post請(qǐng)求的demo練習(xí):
function testPost(){
$.ajax({
type:"POST",//請(qǐng)求的類型 POST GET 無大小寫區(qū)分
url:"http://www.test.com",
data:{name:"post",phone:"3112122"},//post請(qǐng)求的追加參數(shù),與iOS中的字典相同;
datatype: "html",//返回?cái)?shù)據(jù)的格式"xml", "html", "script", "json", "jsonp", "text".
beforeSend:function(){$("#msg").html("logining");},//請(qǐng)求之前調(diào)用的函數(shù)
success:function(data){ ?//請(qǐng)求成功返回調(diào)用的函數(shù)
$("#msg").html(decodeURI(data));
}? ,
//調(diào)用執(zhí)行后調(diào)用的函數(shù)
complete: function(XMLHttpRequest, textStatus){
alert(XMLHttpRequest.responseText);
alert(textStatus);
//HideLoading();},
success :function(data){
//請(qǐng)求成功的處理方法
}
error: function(){
//請(qǐng)求出錯(cuò)處理
}});}
對(duì)ajax的get請(qǐng)求的說明:
url的不同: ? ?url = "update.php?username=" +encodeURIComponent(username) + "&content=" +encodeURIComponent(content)+"&id=1" ;
在ajax請(qǐng)求時(shí) 防止異步請(qǐng)求的方法
//var imgNum = $('img').length;
//$('img').load(function() {
//if (!--imgNum) {
//}
//});
2.獲取到網(wǎng)頁滑動(dòng)的方法,當(dāng)滑動(dòng)到底部的時(shí)候進(jìn)行加載下一頁
$(window).scroll(function() {
var scrollTop = $(this).scrollTop();//方法返回或元素的滾動(dòng)條的垂直位置捂襟。
var scrollHeight = $(document).height();//整篇文章的高度
var windowHeight = $(this).height();//是獲取當(dāng)前 也就是你瀏覽器所能看到的頁面的那部分的高度? 這個(gè)大小在你縮放瀏覽器窗口大小時(shí) 會(huì)改變 與document是不一樣的? 根據(jù)英文應(yīng)該也能理解吧
if(scrollTop + windowHeight >= scrollHeight) {
orderid = $("#orderidHidden").val();
getdata(usertype, notvip, orderid);//執(zhí)行的請(qǐng)求方法
}
});
3. ?關(guān)于window.addeventlistener
當(dāng)對(duì)一個(gè)對(duì)像綁定多個(gè)方法的時(shí)候,之后最后一個(gè)會(huì)生效,使用addeventlistener之后,每一個(gè)方法都是可以執(zhí)行;用來解決讓一個(gè)js事件執(zhí)行多個(gè)函數(shù)
4.關(guān)于 window.orientation
window.addEventListener("onorientationchange" in window ? "orientationchange":"resize",function(){
if (window.orientation===180 ||window.orientation===0){
$('.lock_wrp').CSS("display","none");
console.log('這個(gè)是豎屏展示');}
if (window.orientation===90 ||window.orientation===-90){
$('.lock_wrp').css("display","block");
console.log('這個(gè)是橫屏展示');
e.preventDefault();
});}});
屏幕旋轉(zhuǎn)事件: onorientationchange ? 出自 html5屏幕旋轉(zhuǎn)事件 onorientationchange
function orientationChange() { ?
?switch(window.orientation) {? ??
case 0:? ? ? ? ?
?? alert("肖像模式 0,screen-width: " + screen.width + "; screen-height:" + screen.height);? ? ? ? ? ? break;??
? case -90:? ??
? ? ? ? alert("左旋 -90,screen-width: " + screen.width + "; screen-height:" + screen.height);? ? ? ? ? ? break;? ??
case 90:? ? ? ? ??
? ? alert("右旋 90,screen-width: " + screen.width + "; screen-height:" + screen.height);? ? ? ? ? ? break;? ?
case 180:? ? ? ? ?
alert("風(fēng)景模式 180,screen-width: " + screen.width + "; screen-height:" + screen.height);? ? ? ? break;? ? };
};// 添加事件監(jiān)聽addEventListener('load', function(){? ? orientationChange();? ? window.onorientationchange = orientationChange;});
5.removeAttr() 方法從被選元素中移除屬性涝桅。
6.關(guān)于遍歷數(shù)組的幾種方法;參考:Array.prototype.forEach數(shù)組遍歷
if(!Array.prototype.forEach){
Array.prototype.forEach = function(callback,thisArg){
var T, k;
if(this === null){
throw new TypeError("this is null or not defined")
}
var O = Object(this);
var len = O.length >>> 0;
if(typeof callback !== "function"){
throw new TypeError(callback + " is not a function");
}
if(arguments.length > 1){
T = thisArg;
}
k = 0;
while(k < len){
var kValue;
if(k in O){
kValue = O[k];
callback.call(T,kValue,k,O);
}
k++;
}
}
}