欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery庫文件略龐大用純js替換jquery的方法

 更新時間:2014年08月12日 17:03:41   投稿:whsnow  
jquery庫文件略龐大,因此在某些情況下就需要用純js替換jquery,需要的朋友可以參考下

jquery庫文件略龐大,在某些情況下,需要盡量減少加載的文件(文件大?。?,需要用純js來編寫效果

$('#layer')
document.getElementById('layer')

$('#layer span')
var layer = document.getElementById('layer');
var span = layer.getElementsByTagName('span');

$('#inner').parent()
document.getElementById("inner").parentNode

$(window).width();
document.body.clientWidth

$('#layer').width();
document.getElementById('layer').style.width

$('#wrap').append('<span>a</span>');
var span=document.createElement("span");
span.innerHTML='a';
document.getElementById("wrap").appendChild(span);

$('#wrap span').remove();
deleteSpan();
function deleteSpan(){
var content=document.getElementById("wrap");
var childs=content.getElementsByTagName("span");
if(childs.length > 0){
content.removeChild(childs[childs.length-1]);
deleteSpan();
}
}

$('#wrap').css({'left':'100px'});
var wrap = document.getElementById('wrap');
wrap.style.left = '100px';

$('#banner').hide();
document.getElementById('banner').style.display = 'none';

$('#banner').show();
document.getElementById('banner').style.display = 'block';

$('#people').addClass('people_run2');
document.getElementById("people").classList.add('people_run2');

$('#people').removeClass('people_run1');
document.getElementById("people").classList.remove('people_run1');

$('#number').text(1);
document.getElementById('number').innerHTML = 1;
$.ajax({ 
type: "POST", 
url: 'run.php', 
data: 's='+last_step, 
dataType:"JSON", 
timeout: 2000, 
success: function(data){ 
//處理回調(diào) 
} 
}); 

//1.創(chuàng)建XMLHTTPRequest對象 
var xmlhttp; 
if (window.XMLHttpRequest) { 
//IE7+, Firefox, Chrome, Opera, Safari 
xmlhttp = new XMLHttpRequest; 

//針對某些特定版本的mozillar瀏覽器的bug進(jìn)行修正 
if (xmlhttp.overrideMimeType) { 
xmlhttp.overrideMimeType('text/xml'); 
}; 
} else if (window.ActiveXObject){ 
//IE6, IE5 
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
}; 

if(xmlhttp.upload){ 
//2.回調(diào)函數(shù) 
//onreadystatechange是每次 readyState 屬性改變的時候調(diào)用的事件句柄函數(shù) 
xmlhttp.onreadystatechange = function(e){ 
if(xmlhttp.readyState==4){ 
if(xmlhttp.status==200){ 
var json = eval('(' + xmlhttp.responseText + ')'); 
//處理回調(diào) 
} 
} 
}; 

//3.設(shè)置連接信息 
//初始化HTTP請求參數(shù),但是并不發(fā)送請求。 
//第一個參數(shù)連接方式,第二是url地址,第三個true是異步連接,默認(rèn)是異步 
//使用post方式發(fā)送數(shù)據(jù) 
xmlhttp.open("POST","/run.php",true); 

//4.發(fā)送數(shù)據(jù),開始和服務(wù)器進(jìn)行交互 
//發(fā)送 HTTP 請求,使用傳遞給 open() 方法的參數(shù),以及傳遞給該方法的可選請求中如果true, send這句話會立即執(zhí)行 
//如果是false(同步),send會在服務(wù)器數(shù)據(jù)回來才執(zhí)行 
//get方法在send中不需要內(nèi)容 
var formdata = new FormData(); 
formdata.append("s", last_step); 
xmlhttp.send(formdata); 
}
$('btn').bind({
'touchstart':function(){
}
});
document.getElementById("btn").ontouchstart = function(){
};

相關(guān)文章

最新評論