- 浏览: 1112806 次
文章分类
- 全部博客 (379)
- S2SH (16)
- stuts2 (0)
- java语言 (81)
- JSP (17)
- <html>元素 (11)
- javaweb (4)
- web容器 (3)
- ext (23)
- javaScript (48)
- ant (1)
- liferay (1)
- sql (9)
- css (42)
- 浏览器设置 (3)
- office_world (1)
- eclipse (4)
- 其它 (28)
- 操作系统 (5)
- android (6)
- Struts2 (11)
- RegEx (3)
- mysql (5)
- BigDATA (1)
- Node.js (1)
- Algorithm (10)
- Apache Spark (1)
- 数据库 (5)
- linux (2)
- git (1)
- Adobe (3)
- java语言,WebSocket (1)
- Maven (3)
- SHELL (1)
- XML (2)
- 数学 (2)
- Python (2)
- Java_mysql (1)
- ReactJS (6)
- 养生 (4)
- Docker (1)
- Protocols (3)
- java8 (2)
- 书籍 (1)
- Gradle (2)
- AngularJS (5)
- SpringMVC (2)
- SOAP (1)
- BootstrapCSS (1)
- HTTP协议 (1)
- OAuth2 (1)
最新评论
-
Lixh1986:
Java并发编程:自己动手写一把可重入锁https://blo ...
Java之多线程之Lock与Condition -
Lixh1986:
http://win.51apps.com.cn/https: ...
temp -
ztwsl:
不错,支持很好
HttpServletRequest和ServletRequest的区别 -
guodongkai:
谢谢您能将知识精华汇编总结,让初学者们从原理中学会和提高。
javaScript之function定义 -
kangwen23:
谢谢了,顶顶
struts2中的ValueStack学习
How jQuery Works
1. jQuery: The Basics
This is a basic tutorial, designed to help you get started using jQuery.
If you don't have a test page setup yet, start by creating the following HTML page:
The src attribute in the <script> element must point to a copy of jQuery.
Download a copy of jQuery from the Downloading jQuery page and store the jquery.js file in the same directory as your HTML file.
Note: When you download jQuery, the file name may contain a version number, e.g., jquery-x.y.z.js.
Make sure to either rename this file to jquery.js or update the src attribute of the <script> element to match the file name.
2. Launching Code on Document Ready
To ensure that their code runs after the browser finishes loading the document,
many JavaScript programmers wrap their code in an onload function:
Unfortunately, the code doesn't run until all images are finished downloading, including banner ads.
To run code as soon as the document is ready to be manipulated, jQuery has a statement known as the ready event:
For example, inside the ready event, you can add a click handler to the link:
Copy the above jQuery code into your HTML file where it says "// Your code goes here".
Then, save your HTML file and reload the test page in your browser.
Clicking the link should now first display an alert pop-up,
then continue with the default behavior of navigating to http://jquery.com.
For click and most other events, you can prevent the default behavior
by calling event.preventDefault() in the event handler:
Try replacing your first snippet of jQuery code,
which you previously copied in to your HTML file, with the one above.
Save the HTML file again and reload to try it out.
Complete Example
The following example illustrates the click handling code discussed above,
embedded directly in the HTML <body>. Note that in practice,
it is usually better to place your code in a separate JS file and load it
on the page with a <script> element's src attribute.
http://api.jquery.com/ready/
jQuery offers several ways to attach a function that will run when the DOM is ready. All of the following syntaxes are equivalent:
3. Adding and Removing an HTML Class
Important: You must place the remaining jQuery examples inside the ready event
so that your code executes when the document is ready to be worked on.
Another common task is adding or removing a class.
First, add some style information into the <head> of the document, like this:
Next, add the .addClass() call to the script:
All <a> elements are now bold.
To remove an existing class, use .removeClass():
Special Effects
jQuery also provides some handy effects to help you make your web sites stand out. For example, if you create a click handler of:
Then the link slowly disappears when clicked.
4. Callbacks and Functions
Unlike many other programming languages,
JavaScript enables you to freely pass functions around to be executed at a later time.
A callback is a function that is passed as an argument to another function and is
executed after its parent function has completed.
Callbacks are special because they patiently wait to execute until their parent finishes.
Meanwhile, the browser can be executing other functions or doing all sorts of other work.
To use callbacks, it is important to know how to pass them into their parent function.
4.1 Callback without Arguments
If a callback has no arguments, you can pass it in like this:
When $.get() finishes getting the page myhtmlpage.html, it executes the myCallBack() function.
Note: The second parameter here is simply the function name
(but not as a string, and without parentheses).
4.2 Callback with Arguments
Executing callbacks with arguments can be tricky.
4.2.1 Wrong
This code example will not work:
The reason this fails is that the code executes myCallBack( param1, param2 ) immediately
and then passes myCallBack()'s return value as the second parameter to $.get().
We actually want to pass the function myCallBack(), not myCallBack( param1, param2 )'s return
value (which might or might not be a function).
So, how to pass in myCallBack() and include its arguments?
4.2.2 Right
To defer executing myCallBack() with its parameters, you can use an anonymous function as a wrapper.
Note the use of function() {}. The anonymous function does exactly one thing: calls myCallBack(),
with the values of param1 and param2.
When $.get() finishes getting the page myhtmlpage.html,
it executes the anonymous function, which executes myCallBack( param1, param2 ).
<hr/>
What is the difference between these jQuery ready functions?
Answer:
Link 1.
Link 2.
The two ways are equivalent, I personally prefer the second, $(function() {}); it's just a shortcut for document ready.
About the new jQuery(document)... construct, you don't really need to use the new operator, jQuery will use it internally if you don't.
The argument that the ready handler function receives, is the jQuery object itself.
That's quite useful where you have to run jQuery in compatibility mode with other libraries, for example:
jQuery(function ($) {
// use $ here
});
The $ argument inside the callback will refer to the jQuery object, outside that function it might refer to another library like PrototypeJS.
-
1. jQuery: The Basics
This is a basic tutorial, designed to help you get started using jQuery.
If you don't have a test page setup yet, start by creating the following HTML page:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <a href="http://jquery.com/">jQuery</a> <script src="jquery.js"></script> <script> // Your code goes here. </script> </body> </html>
The src attribute in the <script> element must point to a copy of jQuery.
Download a copy of jQuery from the Downloading jQuery page and store the jquery.js file in the same directory as your HTML file.
Note: When you download jQuery, the file name may contain a version number, e.g., jquery-x.y.z.js.
Make sure to either rename this file to jquery.js or update the src attribute of the <script> element to match the file name.
2. Launching Code on Document Ready
To ensure that their code runs after the browser finishes loading the document,
many JavaScript programmers wrap their code in an onload function:
window.onload = function() { alert( "welcome" ); };
Unfortunately, the code doesn't run until all images are finished downloading, including banner ads.
To run code as soon as the document is ready to be manipulated, jQuery has a statement known as the ready event:
$( document ).ready(function() { // Your code here. });
For example, inside the ready event, you can add a click handler to the link:
$( document ).ready(function() { $( "a" ).click(function( event ) { alert( "Thanks for visiting!" ); }); });
Copy the above jQuery code into your HTML file where it says "// Your code goes here".
Then, save your HTML file and reload the test page in your browser.
Clicking the link should now first display an alert pop-up,
then continue with the default behavior of navigating to http://jquery.com.
For click and most other events, you can prevent the default behavior
by calling event.preventDefault() in the event handler:
$( document ).ready(function() { $( "a" ).click(function( event ) { alert( "As you can see, the link no longer took you to jquery.com" ); event.preventDefault(); }); });
Try replacing your first snippet of jQuery code,
which you previously copied in to your HTML file, with the one above.
Save the HTML file again and reload to try it out.
Complete Example
The following example illustrates the click handling code discussed above,
embedded directly in the HTML <body>. Note that in practice,
it is usually better to place your code in a separate JS file and load it
on the page with a <script> element's src attribute.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <a href="http://jquery.com/">jQuery</a> <script src="jquery.js"></script> <script> $( document ).ready(function() { $( "a" ).click(function( event ) { alert( "The link will no longer take you to jquery.com" ); event.preventDefault(); }); }); </script> </body> </html>
http://api.jquery.com/ready/
jQuery offers several ways to attach a function that will run when the DOM is ready. All of the following syntaxes are equivalent:
// fn is a type of function. // 1. $(fn); // 2. $(document).ready(fn); // 3. $("document").ready(fn); // 4. $("img").ready(fn); // 5. $().ready(fn);
// an implemention of onReady function. // onReady function var onReady = function(fn){ var old = window.onload; if(typeof old != 'function'){ window.onload = fn; }else{ window.onload = function(){ old(); fn(); } } } // An usage of example: onReady(function(){ console.log(1); }); onReady(function(){ console.log(2); }); onReady(function(){ console.log(3); });
3. Adding and Removing an HTML Class
Important: You must place the remaining jQuery examples inside the ready event
so that your code executes when the document is ready to be worked on.
Another common task is adding or removing a class.
First, add some style information into the <head> of the document, like this:
<style> a.test { font-weight: bold; } </style>
Next, add the .addClass() call to the script:
$( "a" ).addClass( "test" );
All <a> elements are now bold.
To remove an existing class, use .removeClass():
$( "a" ).removeClass( "test" );
Special Effects
jQuery also provides some handy effects to help you make your web sites stand out. For example, if you create a click handler of:
$( "a" ).click(function( event ) { event.preventDefault(); $( this ).hide( "slow" ); });
Then the link slowly disappears when clicked.
4. Callbacks and Functions
Unlike many other programming languages,
JavaScript enables you to freely pass functions around to be executed at a later time.
A callback is a function that is passed as an argument to another function and is
executed after its parent function has completed.
Callbacks are special because they patiently wait to execute until their parent finishes.
Meanwhile, the browser can be executing other functions or doing all sorts of other work.
To use callbacks, it is important to know how to pass them into their parent function.
4.1 Callback without Arguments
If a callback has no arguments, you can pass it in like this:
$.get( "myhtmlpage.html", myCallBack );
When $.get() finishes getting the page myhtmlpage.html, it executes the myCallBack() function.
Note: The second parameter here is simply the function name
(but not as a string, and without parentheses).
4.2 Callback with Arguments
Executing callbacks with arguments can be tricky.
4.2.1 Wrong
This code example will not work:
// call myCallback() function immediately. $.get( "myhtmlpage.html", myCallBack( param1, param2 ) );
The reason this fails is that the code executes myCallBack( param1, param2 ) immediately
and then passes myCallBack()'s return value as the second parameter to $.get().
We actually want to pass the function myCallBack(), not myCallBack( param1, param2 )'s return
value (which might or might not be a function).
So, how to pass in myCallBack() and include its arguments?
4.2.2 Right
To defer executing myCallBack() with its parameters, you can use an anonymous function as a wrapper.
Note the use of function() {}. The anonymous function does exactly one thing: calls myCallBack(),
with the values of param1 and param2.
// define an anonymous function, // which invoke myCallback() inside its function body. $.get( "myhtmlpage.html", function() { myCallBack( param1, param2 ); });
When $.get() finishes getting the page myhtmlpage.html,
it executes the anonymous function, which executes myCallBack( param1, param2 ).
<hr/>
What is the difference between these jQuery ready functions?
// what is difference between $(function(){ }); // and $(document).ready(function() { });
Answer:
Link 1.
Link 2.
The two ways are equivalent, I personally prefer the second, $(function() {}); it's just a shortcut for document ready.
About the new jQuery(document)... construct, you don't really need to use the new operator, jQuery will use it internally if you don't.
The argument that the ready handler function receives, is the jQuery object itself.
That's quite useful where you have to run jQuery in compatibility mode with other libraries, for example:
jQuery(function ($) {
// use $ here
});
The $ argument inside the callback will refer to the jQuery object, outside that function it might refer to another library like PrototypeJS.
-
发表评论
-
Javascript 测试框架之 隐式声明 之 describe
2019-06-25 15:26 2590为什么使用 javascript 测试框架时,没有显式导入 d ... -
JavaScript之ECMAScript6新特性之_03_箭头函数(Arrow Function)
2018-01-25 13:46 1117一、简介 箭头函数(Arrow Function)是 ES6 ... -
JavaScript之ECMAScript6新特性之_02_线程异步阻塞: Promise, Async / await
2018-01-12 16:51 2326刚出来不久的 ES8 包含了 async 函数,它的出现,终于 ... -
JavaScript之ECMAScript6新特性之_01_开篇
2017-08-17 02:54 603点此查看全部: http://es6-features.org ... -
jQuery Versions - browser support
2017-08-12 04:19 1617jQuery 3.2.1 Support Deskto ... -
基于HTML5实现的中国象棋游戏
2017-06-24 02:24 1688HTML5实现中国象棋游戏 http://www.w2bc.c ... -
JavaScript之跨域请求解决方案
2017-06-07 11:03 3972浏览器处于安全原因,在使用 Ajax 进行请求访问时,不允许跨 ... -
JavaScript之 25 道面试题
2017-04-17 17:05 95425 Essential JavaScript Intervi ... -
JavaScript小应用之分页算法
2017-03-16 12:56 666效果图: function getPagina ... -
jQuery之empty() VS. remove()
2017-03-16 10:32 721jQuery empty() vs remove() Wh ... -
jQuery之 prop() VS. attr()
2017-03-14 16:43 660attr() 用于自定义属性,id ; prop() 用于 ... -
jQuery之mouseover,mouseover,mouseout,mouseleave
2017-03-14 10:20 655Jquery mouseenter() vs mouseove ... -
javascript之JS操作iframe
2017-02-28 14:56 2193JS操作iframe 1. 获得iframe的w ... -
javascript之面向对象编程之原型继承
2017-01-02 15:34 1127前文讲到“属性继承” ... -
HTML5之Cookie,localStorage 与 sessionStorage
2016-12-22 18:35 844详说 Cookie, LocalStorage 与 ... -
jquery之live(), delegate(), on() 方法
2016-11-26 23:48 927通过下面的一个实例理解 jQuery 的 live(), de ... -
javascript之小应用:网页在线聊天
2016-11-08 11:48 4296概览 这款使用 PHP 和 javascript 搭建的 ... -
javascript之编程序题目
2016-11-06 17:30 10531. 判断两个字符串是否:字母相同切长度相同(空格不算)。 ... -
javascript之面向对象编程之属性继承
2016-10-23 21:09 914函数继承可以分为两种:1、继承其 this 属性 2、继承其 ... -
javascript 之 undefined
2016-08-12 11:01 710一、用法 undefined 关键字有两种用法: 1. 如 ...
相关推荐
通过以上步骤,我们可以创建一个高效的jQuery页内查找功能,帮助用户快速定位到含有特定关键词的页面内容。这个功能不仅适用于文章阅读网站,也可以应用于任何需要搜索页面内文本的场合。熟悉这些技术和技巧将有助于...
教程名称:王兴魁jQuery实战系列视频课程目录:【】CSDN ITCAST王兴魁jQuery参考代码及PDF课件【】JQuery实战第一讲:概述、环境准备及入门实例【】JQuery实战第三讲:横向纵向菜单【】JQuery实战第二讲:可以编辑的...
在本文中,我们将深入探讨如何使用jQuery来创建一个功能丰富的文本框,该文本框能够动态地生成和管理关键词标签。这个功能广泛应用于各种网站,如社交媒体、博客平台、论坛等,帮助用户方便地组织和分类内容。 首先...
**jQuery六边形蜂巢布局关键词标签代码详解** 在网页设计中,为了提供独特且吸引用户的界面,六边形蜂巢布局已经成为一种流行的元素。这种布局方式模仿了自然界中的蜂巢结构,通过六边形的排列,使得内容展示更加...
jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)...
JQuery实战第五讲:级联下拉框效果,如果用在《MVC中更加合适
jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码...
jquery 及其插件集合 包含 AddTxtToCaret:添加文本到光标位置 jquery.colorbox:完美的jquery弹出层支持图片播放 jquery.contextmenu.r2:jquery右键菜单 jquery.cookie:jquery Cookie操作 jquery.form:jquery...
jquery.citypicker.js 包括中国大部分城市。 城市可以自行增加。 很精美的城市选择器,跟日期选择器效果差不多。 最新版本1.1.0 有网友说没有反应。报错!!本人已经有IE6,IE7,IE8,fireFox上测试过了。没有任何问题...
**jQuery库概述** jQuery是JavaScript的一个库,由John Resig在2006年创建,旨在简化HTML文档遍历、事件处理、动画制作和Ajax交互。...对于开发者来说,理解并熟练使用jQuery是提升工作效率的关键步骤。
jQuery2.1.4来自jQuery官方网站,jQuery2.1.4包括jQuery2.1.4和jQuery2.1.4压缩版,即:jQuery2.1.4.js和jQuery2.1.4.min.js,jQuery是流行的JS框架! jquery-2.1.4 (注!jquery-2.0以上版本不再支持IE 6/7/8) ...
Note: the latest edition of this book is jQuery: Novice to Ninja: New Kicks And Tricks jQuery: Novice to Ninja is your fast track to mastering jQuery—the all-conquering JavaScript framework. Used by...
、CSS和JavaScript知识的开发者,内容覆盖了jQuery知识体系的全部内容,包括jQuery Core、jQuery Plugin 、jQuery UI、jQuery Mobile以及大量第三方的插件库和2800多个应用jQuery技术的网页参考。
JavaScript+jQuery 网页特效设计 jQuery(3.4.1)基础 1 jQuery简介 jQuery优势 jQuery安装 jQuery语法 1、jQuery简介 1.1 学习jQuery之前,需要以下基础知识 HTML CSS JavaScript 1、jQuery简介 1.2 什么是jQuery? ...
通过观察和分析这个示例,你可以更深入地理解`jQuery Migrate`如何工作,并学习如何在自己的项目中应用。 **5. 逐步更新和最佳实践** 虽然`jQuery Migrate`可以帮助你过渡到新版本,但长期依赖它是不可取的。最好...
官网jquery压缩版引用地址: <script src="https://code.jquery.com/jquery-3.6.1.min.js"></script> 下载后更改文件名,匹配引用连接名称 适配3.6.1版本 jquery-3.6.1.min.js jquery-3.6.1.min.js 建议网络环境不好...
《jQuery关键词组拆分工具插件详解》 在Web开发中,jQuery库以其简洁的API和强大的功能,深受开发者喜爱。对于数据处理,尤其是文本数据,关键词的提取和拆分是一项常见任务。针对这一需求,出现了jQuery关键词组...
本示例中的"jQuery查找关键词文字高亮显示代码"是一个实用的功能,用于提升用户体验,特别是在用户进行搜索时。当用户在搜索框中输入关键词后,页面上与关键词匹配的部分会被高亮显示,使得用户能快速定位到相关内容...
"jquery-3.4.1_sangat1_jquery3.4.1"可能指的是一个特定的项目或者命名约定,"sangat1"可能是项目名或者是个人开发者的名字,而"jquery3.4.1"是jQuery库的另一种写法,它们都指向同一种资源——jQuery 3.4.1。...
jQuery 是一个广泛使用的JavaScript库,由John Resig于2006年创建,它极大地简化了JavaScript编程,尤其是处理DOM操作、事件处理、动画效果和Ajax交互。jQuery 的设计目标是“write less, do more”,它通过提供简洁...