Instructions for using jQuery

php中世界最好的语言
Release: 2018-05-24 11:54:43
Original
1147 people have browsed it

This time I will bring you the instructions for using jQuery. What are the precautions for using jQuery? The following is a practical case, let’s take a look.

jQuerySelector$("jQuery Selector")is the same ascss Selector, it can be.Can be#Can betag

$("p") $(".color") $("#mylove") $("p ul .yellow") $("#color.yellow")
Copy after login

When the page is ready

jQuery: $(document).ready(function(){ //your code }); JavaScript: window.onload=function(){ //your code };
Copy after login

Listen for events

  • Binding event

    jQuery: $("#click").bind("click",function(){ //jQuery自动判断浏览器类型并做调整 //your code }); JavaScript: var click=document.getElementById("click"); if(window.attachEvent){ click.attachEvent("click",function(){ //IE8或之前 //your code }); }else{ click.addEventListener("click",function(){ //除了IE8或之前 //your code }); }
    Copy after login
  • Unbinding event

    jQuery: //jQuery自动判断浏览器类型并做调整 $("#click").unbind("click"); 删除 click 事件 $("#click").unbind(); 删除所有事件 JavaScript: var click=document.getElementById("click"); click.removeEventListener("click"); //除了IE8或之前 click.detachEvent("click"); //IE8或之前
    Copy after login
  • Click

    jQuery: $("#click").click(function(){ //your code }); JavaScript: document.getElementById("click").onclick=function(){ //your code };
    Copy after login

Traversal

  • each()

    jQuery: $("p").each(function(){ //your code }); JavaScript: var p=documentElementsByTagName("p"); for(var i in p){ p[i] = //yourcode; };
    Copy after login

jQuery integrates many effects and is easy to use

slideUP() 向上收起 slideDown() 向下展开 slideToggle() fadeIn(速度/ms) 渐入 $.contains(xxx,yyy); 判断 元素xxx 中是不是有 元素yyy
Copy after login

Operations on elements

this

jQuery: $(this).click(function(){}); JavaScript: this.click=function(){};
Copy after login

Operations onCSS

There are ## in jQuery #addClass,removeClasssuch commands to directly operate ona single CSS classJavaScript has
className,classListSuch a command can only operate onall CSS classes

jQuery: $("p").addClass("yellow"); $("p").removeClass("yellow"); JavaScript: p.className= //your code; p.classList.add(""); p.classList.remove("");
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the use of js prototype

Detailed explanation of the steps of combining React with TypeScript and Mobx

The above is the detailed content of Instructions for using jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!