日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

ajax each html 太多,HTML5学习小记二ajax,window.orientation,prototype.forEach

發(fā)布時間:2023/12/15 HTML 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ajax each html 太多,HTML5学习小记二ajax,window.orientation,prototype.forEach 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.ajax的學(xué)習(xí)

HTML5中的ajax相當(dāng)于iOS中的afnetworking;詳見jQuery ajax - ajax() 方法;

對ajax使用post請求的demo練習(xí):

function testPost(){

$.ajax({

type:"POST",//請求的類型 POST GET 無大小寫區(qū)分

url:"http://www.test.com",

data:{name:"post",phone:"3112122"},//post請求的追加參數(shù),與iOS中的字典相同;

datatype: "html",//返回數(shù)據(jù)的格式"xml", "html", "script", "json", "jsonp", "text".

beforeSend:function(){$("#msg").html("logining");},//請求之前調(diào)用的函數(shù)

success:function(data){ ?//請求成功返回調(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){

//請求成功的處理方法

}

error: function(){

//請求出錯處理

}});}

對ajax的get請求的說明:

url的不同: ? ?url = "update.php?username=" +encodeURIComponent(username) + "&content=" +encodeURIComponent(content)+"&id=1" ;

在ajax請求時 防止異步請求的方法

//var imgNum = $('img').length;

//$('img').load(function() {

//if (!--imgNum) {

//}

//});

2.獲取到網(wǎng)頁滑動的方法,當(dāng)滑動到底部的時候進行加載下一頁

$(window).scroll(function() {

var scrollTop = $(this).scrollTop();//方法返回或元素的滾動條的垂直位置。

var scrollHeight = $(document).height();//整篇文章的高度

var windowHeight = $(this).height();//是獲取當(dāng)前 也就是你瀏覽器所能看到的頁面的那部分的高度? 這個大小在你縮放瀏覽器窗口大小時 會改變 與document是不一樣的? 根據(jù)英文應(yīng)該也能理解吧

if(scrollTop + windowHeight >= scrollHeight) {

orderid = $("#orderidHidden").val();

getdata(usertype, notvip, orderid);//執(zhí)行的請求方法

}

});

3. ?關(guān)于window.addeventlistener

當(dāng)對一個對像綁定多個方法的時候,之后最后一個會生效,使用addeventlistener之后,每一個方法都是可以執(zhí)行;用來解決讓一個js事件執(zhí)行多個函數(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('這個是豎屏展示');}

if (window.orientation===90 ||window.orientation===-90){

$('.lock_wrp').css("display","block");

console.log('這個是橫屏展示');

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() 方法從被選元素中移除屬性。

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++;

}

}

}

總結(jié)

以上是生活随笔為你收集整理的ajax each html 太多,HTML5学习小记二ajax,window.orientation,prototype.forEach的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。