zoukankan      html  css  js  c++  java
  • js与jQuery常用方法

    综合了一下JS与jQuery中一些常用的东西,但还是有好多没有补充的,今天就先写这么一点了,下次再继续补啦!

    方法 JavaScript jQuery
    获取节点

    document.getElementById();document.getElementByClassName();

    document.getElementByTagName();document.getElementByName();

    document.querySelector("#Id");document.querySelectorAll(".class");

    $("#ID");$(".class");

    $("TagName");

    获取元素内容

    document.getElementById().innerHtml;

    document.getElementById().textContent;

    $("#ID").html();

    $("#ID").text();

    获取表单值 document.getElementById().value; $("input").val();
    获取属性 document.getElementById().getAttribute("class"); $("#Id").attr("class")
    删除属性 document.getElementById().removeAttribute("class"); $("#Id").removeAttr("class")
    设置属性 document.getElementById().setAttribute();  
    设置样式
     
    获取样式
     
    document.getElementById().style.height = "";
     
    获取行内样式 :ele.style.color;
    低版本IE获取样式值:ele.currentStyle.color;
    其他浏览器获取样式值 :window.getComputedStyle(ele,null).color
     
    $("#id").css("height","200px")
     
    $("id").css('height')
     绑定事件  
    var div = document.getElementById();
    addEvent(t,"click",function(){});
      $("#id").on("click",function(){})
    获取当前时间 $.now new Date().getTime();
     方法 JavaScript jQuery
     文档就绪函数 window.onload = function(){} $(document).ready(function(){});  $(function(){});
    隐藏显示  document.getElementById().style.display = "none/block"
    $("#id").show();
    $("#id").hide();
    创建元素 createElement('div') $('<div>')
    移除元素 removeChild() .remove()
    克隆元素 cloneNode(true) .clone()
    添加元素 insertBefore()、appendChild() .insertBefore()  、insertAfter() 、.append() 
    替换元素 replaceChild()  
    json序列化 JSON.stringify({name:"TG"}) $.stringify({name:"TG"})
    json反序列化 JSON.parse('{"name":"TG"}') $.parseJSON('{"name":"TG"}')
     
     
     方法 JavaScript jQuery
    AJAX的GET
    var xhr = new XMLHttpRequest();
    xhr.open('GET','handle.php?name=zhangSan',true)
    $.get("handle.php",{name:"zhangSan"},function(data){})
    AJAX的POST
    var xhr = new XMLHttpRequest();
    xhr.open('POST','handle.php',true);
    xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xhr.onreadystatechange = function(){}
    xhr.send(null);
    $.post("handle.php",{name:"zhangSan"},function(data){})
  • 相关阅读:
    57. Insert Interval
    56. Merge Intervals
    55. Jump Game
    54. Spiral Matrix
    52. N-Queens II
    More Effective C++ 条款2 最好使用C++转型操作符
    More Effective C++ 条款1 仔细区别pointers和references
    Python_内置函数之max
    python_超级基础
    python_format格式化输出、while else、逻辑运算符、编码初识
  • 原文地址:https://www.cnblogs.com/sunshine-my/p/6592224.html
Copyright © 2011-2022 走看看