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. 后端程序员之路 52、A Tour of Go-2

    # flowcontrol    - for        - for i := 0; i < 10; i++ {        - for ; sum < 1000; {        ...

  2. JVM之类加载器子系统

    类加载器子系统 作用 负责从文件系统或网络系统中加载class文件,class文件在开头有特殊的标记(魔术开头CA FE BA BE) ClassLoader只负责加载class文件,至于能否运行,由 ...

  3. JVM笔记 -- JVM的发展以及基于栈的指令集架构

    2011年,JDK7发布,1.7u4中,开始启用新的垃圾回收器G1(但是不是默认). 2017年,发布JDK9,G1成为默认GC,代替CMS.(一般公司使用jdk8的时候,会通过参数,指定GC为G1) ...

  4. go中errgroup源码解读

    errgroup 前言 如何使用 实现原理 WithContext Go Wait 错误的使用 总结 errgroup 前言 来看下errgroup的实现 如何使用 func main() { var ...

  5. apicloud打包的ios证书的获取方法

    apicloud云编译的时候,需要测试证书或者正式证书进行编译. 那么这个证书是怎么来的呢?通过什么渠道可以获取呢? 这里我介绍下使用香蕉云编这个在线工具来生成: 1.登录香蕉云编,生成证书的csr文 ...

  6. 如何安装jenkins并简单的使用

    如何安装jenkins并使用 一.jenkins 简介: Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括 : 1.持续的软件版本发布/测试项目: 2.监控外部调用 ...

  7. 【odoo14】第五章、服务器侧开发-基础

    本章包含如下内容: 定义模型方法和使用api装饰器 向用户反馈错误信息 针对不同的对象获取空数据集 创建新纪录 更新数据集数据 搜索数据 组合数据集 过滤数据集 遍历记录集 排序数据集 重写已有业务逻 ...

  8. [POJ2828] Buy Tickets(待续)

    [POJ2828] Buy Tickets(待续) 题目大意:多组测试,每组给出\(n\)条信息\((a,b)\),表示\(b\)前面有\(a\)个人,顺序靠后的信息优先级高 Solution.1 由 ...

  9. Spring(一):Spring概述及相关概念

    Spring简介 Spring主要作用是用来解耦,降低代码之间的耦合度.根据功能的不同,可以将系统的代码分为主业务逻辑与系统服务逻辑. 主业务逻辑之间代码联系紧密,相互调用较多,复用性相对较低: 系统 ...

  10. io流(对象流总结)

    对象流 对象流就是对引用数据类型进行操作 序列化:将对象的状态信息转换为可以存储或传输的形式的过程,因此类需要序列化后才可以存储到文件中 对象输出流: 很简单,就三句话,将把一个对象导入指定文件中,要 ...