The jquery library file is a little large and the jquery method is replaced by pure js, And the jquery library js is replaced

Source: Internet
Author: User

The jquery library file is a little large and the jquery method is replaced by pure js, And the jquery library js is replaced

Jquery library files are a little large. In some cases, you need to minimize the size of the loaded files (file size) and use pure js to compile the results.

$('#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) {// processing callback }}); // 1. create the XMLHTTPRequest object var xmlhttp; if (window. XMLHttpRequest) {// IE7 +, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest; // fix bugs in some specific versions of the javasillar browser if (xmlhttp. overrideMimeType) {xmlhttp. overrideMimeType ('text/xml') ;};} else if (window. activeXObject) {// IE6, IE5 xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ") ;}; if (xmlhttp. upload) {// 2. the callback function // onreadystatechange is the event handle function xmlhttp called every time the readyState attribute changes. onreadystatechange = function (e) {if (xmlhttp. readyState = 4) {if (xmlhttp. status = 200) {var json = eval ('+ xmlhttp. responseText + '); // process callback }}; // 3. set connection information // initialize HTTP request parameters, but do not send requests. // The first parameter connection method, the second is the url address, and the third true is the asynchronous connection. The default value is asynchronous // the post method is used to send data xmlhttp. open ("POST", "/run. php ", true); // 4. send data, start interacting with the server // send an HTTP request, use the parameters passed to the open () method, and the optional requests passed to the method if true, the send statement will be executed immediately // if it is false (synchronous ), the send method is executed only when the server data is returned. // The get method does not require the content var formdata = new FormData (); formdata. append ("s", last_step); xmlhttp. send (formdata );}
$('btn').bind({'touchstart':function(){}});document.getElementById("btn").ontouchstart = function(){};

Jquery or js page content replacement

Get innerHtml, replace it, And then assign it to innerHtml

Replace jQuery syntax with js syntax

The following is a method completed with pure js <script type = "text/javascript"> window. onload = function () {// here you want to customize the id var html = "test"; // call the method to execute the loop AlterImg ("test ");} function AlterImg (html) {// obtain the control var obj = document with id = html. getElementById (html); // query all img var imgs = obj. getElementsByTagName ("img"); var length = imgs. length; // cyclically judge for (var I = 0; I <length; I ++) {// obtain the txturlPath attribute var txturlPath = imgs [I]. getAttribute ("txturlPath"); // if the property value is = txturlPath, alert (1); if (txturlPath = "txturlPath") {alert (1 );}}} </script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.