jquery库文件略庞大用纯js替换jquery的方法
2023-06-13 09:15:42 时间
jquery库文件略庞大,在某些情况下,需要尽量减少加载的文件(文件大小),需要用纯js来编写效果
$("#layer") document.getElementById("layer") $("#layerspan") varlayer=document.getElementById("layer"); varspan=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>"); varspan=document.createElement("span"); span.innerHTML="a"; document.getElementById("wrap").appendChild(span); $("#wrapspan").remove(); deleteSpan(); functiondeleteSpan(){ varcontent=document.getElementById("wrap"); varchilds=content.getElementsByTagName("span"); if(childs.length>0){ content.removeChild(childs[childs.length-1]); deleteSpan(); } } $("#wrap").css({"left":"100px"}); varwrap=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){ //处理回调 } }); //1.创建XMLHTTPRequest对象 varxmlhttp; if(window.XMLHttpRequest){ //IE7+,Firefox,Chrome,Opera,Safari xmlhttp=newXMLHttpRequest; //针对某些特定版本的mozillar浏览器的bug进行修正 if(xmlhttp.overrideMimeType){ xmlhttp.overrideMimeType("text/xml"); }; }elseif(window.ActiveXObject){ //IE6,IE5 xmlhttp=newActiveXObject("Microsoft.XMLHTTP"); }; if(xmlhttp.upload){ //2.回调函数 //onreadystatechange是每次readyState属性改变的时候调用的事件句柄函数 xmlhttp.onreadystatechange=function(e){ if(xmlhttp.readyState==4){ if(xmlhttp.status==200){ varjson=eval("("+xmlhttp.responseText+")"); //处理回调 } } }; //3.设置连接信息 //初始化HTTP请求参数,但是并不发送请求。 //第一个参数连接方式,第二是url地址,第三个true是异步连接,默认是异步 //使用post方式发送数据 xmlhttp.open("POST","/run.php",true); //4.发送数据,开始和服务器进行交互 //发送HTTP请求,使用传递给open()方法的参数,以及传递给该方法的可选请求中如果true,send这句话会立即执行 //如果是false(同步),send会在服务器数据回来才执行 //get方法在send中不需要内容 varformdata=newFormData(); formdata.append("s",last_step); xmlhttp.send(formdata); }
$("btn").bind({ "touchstart":function(){ } }); document.getElementById("btn").ontouchstart=function(){ };
相关文章
- JS算法探险之字符串
- 中文参数乱码问题——js字符串编码
- 【说站】js中every方法怎么用?
- JS获取当前年份_js获取当前时间年月日
- Vue.js – 引入外部 JS 文件
- js获取当前年月日时分秒_js获取当前系统时间年月日
- 【JS 逆向百例】猿人学系列 web 比赛第五题:js 混淆 - 乱码增强,详细剖析
- js 实现贪吃蛇游戏
- 重学JS-1.2-知识点:ECMAScript简介
- jQuery图片切换插件jquery.cycle.js详解编程语言
- js循环复制一个div详解编程语言
- 使用Oracle和JS开发新一代应用仿真世界(oracle js)
- 代码精简的可以实现元素圆角的js函数
- jQuery技巧大放送学习jquery的朋友可以看下
- html锁定页面(js遮罩层弹出div效果)
- js和jquery批量绑定事件传参数一(新猪猪原创)
- 兼容IE与firefox火狐的回车事件(js与jquery)
- jQuery在vs2008及js文件中的无智能提示的解决方法
- 检测jQuery.js是否已加载的判断代码
- 远离JS灾难css灾难之js私有函数和css选择器作为容器
- js的压缩及jquery压缩探讨(提高页面加载性能/保护劳动成果)
- jquery库或JS文件在eclipse下报错问题解决方法
- 三种动态加载js的jquery实例代码另附去除js方法
- 自己使用js/jquery写的一个定制对话框控件
- Jquery操作js数组及对象示例代码
- js读写json文件实例代码
- JS取得绝对路径的实现代码