Review: JQuery
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的更多相关文章
- jquery css 简单笔记
内容 要点:清空表单中所有数据,除去 button,submit,reset,hidden 的数据 $(':input','#myform') .not(':button, :submit, :res ...
- review的一个收获popstate,addEventListener:false ,split,jquery cache
一.popstate:记录url历史变化 二.document.location.hash:锚点后面的东西 三.addEventListener:false 是否在捕获或者冒泡事件中执行 强转换 四. ...
- jQuery学习路线&review
学习途径:http://www.w3school.com.cn/jquery/index.asp 路线图 转载自:https://www.cnblogs.com/lanren2017/p/723720 ...
- 15个最佳的代码评审(Code Review)工具
代码评审可以被看作是计算机源代码的测试,它的目的是查找和修复引入到开发阶段的应用程序的错误,提高软件的整体素质和开发者的技能.代码审查程序以各种形式,如结对编程,代码抽查等.在这个列表中,我们编制了1 ...
- jquery require.js AMD
一.为什么要用require.js? 最早的时候,所有Javascript代码都写在一个文件里面,只要加载这一个文件就够了.后来,代码越来越多,一个文件不够了,必须分成多个文件,依次加载.下面的网页代 ...
- jQuery常用技巧-使用的总结
1.关于页面元素的引用 通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用do ...
- 错误源:WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).
Server Error in '/' Application. WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping ...
- Jquery选择器之父节点的子节点
今天review代码,发现有哥们这么写 var span = $($("span"),$("#main")); 我百思不得其解,$(a,b)又好像在哪里见过,后 ...
- jquery遍历集合&数组&标签
jquery遍历集合&数组的两种方式 CreateTime--2017年4月24日08:31:49Author:Marydon 方法一: $(function(){ $("inp ...
随机推荐
- nacos服务注册之服务器端Distro
一致性协议算法Distro阿里自己的创的算法吧,网上能找到的资料很少.Distro用于处理ephemeral类型数据 Distro协议算法看代码大体流程是: nacos启动首先从其他远程节点同步全部数 ...
- uni-app创建项目
下载 HBuilderX 下载地址(https://www.dcloud.io/hbuilderx.html) HBuilderX是通用的前端开发工具,但为uni-app做了特别强化. 创建uni ...
- Java 面向对象 04
面向对象·四级 多态的概述及其代码实现 * A:多态(polymorphic)概述 * 事物存在的多种形态 * B:多态前提 * a:要有继承关系 * b:要有方法重写 * c: 要有父类引用指向子类 ...
- 2020年12月-第01阶段-前端基础-认识HTML
1. HTML 初识 HTML 指的是超文本标记语言 (Hyper Text Markup Language)是用来描述网页的一种语言. HTML 不是一种编程语言,而是一种标记语言 (markup ...
- PowerShell的使用
一:基于winserver2008版本powershell2.0的升级(至4.0) (1)首先:查看各版本的Powershell版本,如下所示: (2)打开虚拟机winserv ...
- linux 设置DNS解决,不能ping 域名的问题
vi /etc/resolv.conf nameserver 114.114.114.114
- 使用函数式语言实践DDD
长期以来我都在实践OOP,进而通过OOP来实现DDD,特别是如何通过面向对象的技巧来建立一个领域模型.OO的一些特性在建立领域模型时显得恰如其分,能否掌握OO的技巧,对创建领域模型有着至关重要的作用. ...
- apk、dex完整性验证
对Dex进行完整性的检查,可通过CRC,或者Hash值.可将校验值放到String资源文件里,或者放到服务器中. 1. 在代码中完成校验值对比逻辑,此部分代码后续不能再改变,否则CRC值会发生变化: ...
- PTA 求二叉树的深度
6-7 求二叉树的深度 (6 分) 本题要求实现一个函数,可返回二叉树的深度. 函数接口定义: int Depth(BiTree T); T是二叉树树根指针,函数Depth返回二叉树的深度,若树为 ...
- SpringBoot学习笔记(四)
本文主要介绍:SpringBoot开发中如何自定义starter 1.什么是starter Starter可以理解为一个可拔插式的插件,提供一系列便利的依赖描述符,您可以获得所需的所有Spring和相 ...