zoukankan      html  css  js  c++  java
  • JQUERY的一些基本用法

     JS方式
     1.根据ID取元素,DOM对象
     var div = document.getElementById("one");
     2.根据class取元素
     var div = document.getElementsByClassName("test");
     3.根据name取
     var bd = document.getElementsByName("uid");
     4.根据标签名取
     var div = document.getElementsByTagName("div");
     
     操作内容
     1.非表单元素
     alert(div.innerText);
     div.innerText = "aaaa";
     div.innerHTML;
     2.表单元素
     div.value
     
     操作属性
     div.setAttribute("","");
     div.removeAttribute("");
     div.getAttribute("");
     
     操作样式
     div.style.backgroundColor = "red";
     alert(div.style.color);只能获取内联样式
     
     在数组里面如果要取DOM对象使用索引的方式,如果要取Jquery对象使用eq()
     
     JQUERY方式
     1.根据ID取元素,Jquery对象
     var div = $("#one");
     2.根据class取
     var div = $(".test");
     3.根据属性取
     var bd = $("[bs='aa']");
     4.根据标签名取
     var div = $("div");
     5.组合选取
     var div = $("div span");
     
     
     操作内容
     1.非表单元素
     alert(div.text());
     div.text("aaaa");
     div.html();
     2.表单元素
     div.val("aaa");
     
     操作属性
     div.attr("test","aa");
     div.removeAttr("test");
     div.attr("test");
     
     操作样式
     div.css("background-color","yellow");
     alert(div.css("color"));
     
     操作元素
     var str = "<div id='a' style='100px; height:100px; background-color:red'></div>";
     
     div.append(str); //追加元素
     $("#a").remove(); //移除某个元素
     
     $(".test").click(function(){
      alert($(this).text());
      
      })
      
     
     $(".test").bind("click",function(){
      
      alert($(this).text());
      
      });
      
     $("#btn").click(function(){
      
      $(".test").unbind("click");
      
      });
     $("#add").click(function(){
      
      $(".test").bind("click",function(){
      
      alert($(this).text());
      
       });
      });
     
    });

  • 相关阅读:
    小程序开发之初体验
    phantomjs 爬去动态页面
    css实现三角形
    多种方式实现千位分隔符
    基于浏览器的人脸识别标记
    Axios源码阅读笔记#1 默认配置项
    基于图形检测API(shape detection API)的人脸检测
    页面性能优化
    目标
    HelloWorld!
  • 原文地址:https://www.cnblogs.com/qz1234/p/5600785.html
Copyright © 2011-2022 走看看