1.DOM access with jQuery

1 $("h1");     //select all the h1s
2 $("#heading"); // selects the element with id of "heading"
3 $(".waring"); //selects all the element with class name of "warning"

The jQuery function can be named $ or jQuery

$("h1");

//have the same effect
jQuery("h1");

2.DOM modification with jQuery

// Set their inner text with text().
$("h1").text("All about cats"); //Set their inner html with html().
$("h1").html("I <strong>love</strong> cats"); //set attributes with attr();
$(".dog-pic").attr("src", "dog.jpg");
$(".google-link").attr("href", "http://www.google.com"); //change CSS styles with css().
$("h1").css("font-family", "monospace");
$("h1").css({"font-family": "monospace", "color": "red"}); //add a class name with addClass().
$("h1").addClass("warning"); //create new element
var $p = $("<p>");
var $p = $('<p style="color:red;">I love people who love cats.</p>'); //append().
$("#main-div").append($p); //insert element by prepend() or appendTo().
$("#dessert").prepend("<div class='scoop " + flavors[indexNumber] + "'></div>"); $alone.appendTo("#party");

3.jQuery collections & looping

jQuery collections

1 //when you use jQuery to find elements,
2 //jQuery return back a jQuery collection object.
3 var $heading = $('h1');
4
5 //turn a DOM node into a jQuery object
6 var $heading = $(heading);
7
8 //retrieve the DOM node out of a jQuery object
9 var heading = $heading[0];

looping through collections

1 // jQuery's each():
2 $("p").each(function(index, element) {
3 $(element).text( $(element).text() + "!!");
4 });
5
6 // this keyword
7 $("p").each(function() {
8 $(this).text( $(this).text() + "!!");
9 });

4.DOM events in jQuery

Adding an event listener

1 $("#save-button").on("click", function() {
2 // handle click event
3 });
4
5 $("#face-pic").on("click", function(event) {
6 var mouseX = event.pageX;
7 var mouseY = event.pageY;
8 });

Triggering events

1 $("#save-button").trigger("click");

checking DOM readiness

$(document).ready(function() {
$("h1").text("Y'all ready for this?");
}); //pass your code to the jQuery function:
$(function() {
$("h1").text("Y'all ready for this?");
});

5.Processing forms with jQuery

// add an event listener to the form element
$("form").on("submit", function() {
// process form
}); // If you are processing the form entirely in jQuery,
//then you should call preventDefault() to prevent the page reloading
$("form").on("submit", function(event) {
event.preventDefault();
// process form
}); // filled out for an input in a form
// you should typically use val() var answer = $("#answer").val(); // Inside the callback function, you can reference
// the form element using the this keyword. $("form").on("submit", function() {
// store the value of the input with name='age'
var age = $(this).find('[name=age]').val();
});

6.DOM animation in jQuery

Changing visbility

// for some visibility change
$("#pic").hide();
$("#pic").show();
$("#pic").toggle(); //You can pass a callback function as the second
//parameter to any of those functions
$("#pic").toggle(1000, function() {
$("body").append("It's here!");
}); // chain multiple effects together
$("#pic").slideUp(300).delay().fadeIn();

custom animation

$("#pic").animate({
width: "70%",
opacity: 0.7,
padding: 20
}, 1000);

Review: JQuery的更多相关文章

  1. jquery css 简单笔记

    内容 要点:清空表单中所有数据,除去 button,submit,reset,hidden 的数据 $(':input','#myform') .not(':button, :submit, :res ...

  2. review的一个收获popstate,addEventListener:false ,split,jquery cache

    一.popstate:记录url历史变化 二.document.location.hash:锚点后面的东西 三.addEventListener:false 是否在捕获或者冒泡事件中执行 强转换 四. ...

  3. jQuery学习路线&review

    学习途径:http://www.w3school.com.cn/jquery/index.asp 路线图 转载自:https://www.cnblogs.com/lanren2017/p/723720 ...

  4. 15个最佳的代码评审(Code Review)工具

    代码评审可以被看作是计算机源代码的测试,它的目的是查找和修复引入到开发阶段的应用程序的错误,提高软件的整体素质和开发者的技能.代码审查程序以各种形式,如结对编程,代码抽查等.在这个列表中,我们编制了1 ...

  5. jquery require.js AMD

    一.为什么要用require.js? 最早的时候,所有Javascript代码都写在一个文件里面,只要加载这一个文件就够了.后来,代码越来越多,一个文件不够了,必须分成多个文件,依次加载.下面的网页代 ...

  6. jQuery常用技巧-使用的总结

    1.关于页面元素的引用 通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用do ...

  7. 错误源:WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).

    Server Error in '/' Application. WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping ...

  8. Jquery选择器之父节点的子节点

    今天review代码,发现有哥们这么写 var span = $($("span"),$("#main")); 我百思不得其解,$(a,b)又好像在哪里见过,后 ...

  9. jquery遍历集合&数组&标签

      jquery遍历集合&数组的两种方式 CreateTime--2017年4月24日08:31:49Author:Marydon 方法一: $(function(){ $("inp ...

随机推荐

  1. Django中文文档-模型Models(二):Meta选项、模型属性、模型方法

    元数据(Meta)选项 使用内部的class Meta 定义模型的元数据,例如: from django.db import models class Ox(models.Model): horn_l ...

  2. FFT HDL Optimized模块HDL综合代码生成及与Xilinx xfft IP MEX接口精度详细比较

    前面一篇随笔叙述了关于MATLAB中FFT_HDL_Optimzed模块定点(IEEE754单精度float格式)二进制与十进制转换实现,有需要的往前翻一下即可.这一篇随笔将叙述 FFT HDL Op ...

  3. pytorch(04)简单的线性回归

    线性回归 线性回归是分析一个变量与另外一个变量之间关系的方法 因变量:y 自变量:x 关系:线性 y = wx+b 分析:求解w,b 求解步骤: 确定模型,Model:y = wx+b 选择损失函数, ...

  4. 《Asp.Net Core3 + Vue3入坑教程》 - 6.异常处理与UserFriendlyException

    简介 <Asp.Net Core3 + Vue3入坑教程> 此教程适合新手入门或者前后端分离尝试者.可以根据图文一步一步进操作编码也可以选择直接查看源码.每一篇文章都有对应的源码 目录 & ...

  5. 漫漫Java路1—基础知识—初涉java

    前言 主学信息安全,在编程的路上还是一个孩子,还在一步一步探索,有些东西可能是站在自己的位置思考的,很可能会出现一些啼笑皆非的错误,如果有误,还希望各位斧正. Java安装 jdk的安装 甲骨文官网选 ...

  6. Why系列:谨慎使用delete

    题外话 这里大家可能要笑了,这不就一个操作符吗,还用单独来讲. 有这时间,还不如去看看react源码,vue源码. 我说:react源码会去看的,但是这个也很重要. delete你了解多少 这里提几个 ...

  7. ASP.NET跨域访问解决

    第一种: step1:添加引用(搜索CORS) step2: App_Start/WebApiConfig.cs中添加配置 step3: 在控制器中添加特性 第二种: 在App_Start/WebAp ...

  8. Hznu_0j 1533 计算球体积(水)

    题意:根据输入的半径值,计算球的体积: Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径. Output 输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数. ...

  9. 使用MyBatis的步骤

    1.创建空的Java工程,安装MyBatis依赖 <?xml version="1.0" encoding="UTF-8"?> <projec ...

  10. 2021年的UWP(6)——长生命周期Desktop Extension向UWP的反向通知

    上一篇我们讨论了UWP和Desktop Extension间的双向通讯,适用于Desktop Extension中存在用户交互的场景.本篇我们讨论最后一种情况,与前者不同的是,Desktop Exte ...