选择器(selector) 以及 事件(event)
$(document).ready(function() {
$("a").click(function() {
alert("Hello world!");
});
});
这段话的意义是,当页面载入完毕,jquery能加载所有的dom元素,并且选择了一个a标签,封装成jquery object (jquery对象),然后调用jquery object 的click方法,触发了所提供的alert方法。
addclass 方法
$(document).ready(function() {
$("#orderedlist").addClass("red");
});
这段话的意思是,把css中的id选择器封装为jquery对象,并且调用addclass方法来加载class为red的css
find和each方法
$(document).ready(function() {
$("#orderedlist").find("li").each(function(i) {
$(this).html( $(this).html() + " BAM! " + i );
});
});
这段话的意思是,用FIND找到所有的li标签,然后迭代每一个li,然后完成函数中的操作。
这里第一个HTML()是获取HTML,而html()是赋值
not和filter方法
:has()
$(document).ready(function() {
$("li").not(":has(ul)").css("border", "1px solid black");
});
这段话的意思是,过滤所有的li,把li中不含ul标签的全部加在一个css
not():
filter():
2个方法的区别在于2者正好相反。如果本列,filter就是把含ul标签的加一个css
end方法
slideUp
slideDown
:visible
$(document).ready(function() {
$('#faq').find('dd').hide().end().find('dt').click(function() {
var answer = $(this).next();
if (answer.is(':visible')) {
answer.slideUp();
} else {
answer.slideDown();
}
});
});
实现的功能是收缩答案功能。像'#faq' 只选择了一次,利用end()方法,第一次find()方法会结束(undone),所以我们可以接着在后面继续find('dt'),而不需要再写$('#faq').find('dt')。
hover 方法
$(document).ready(function() {
$("a").hover(function() {
$(this).parents("p").addClass("highlight");
}, function() {
$(this).parents("p").removeClass("highlight");
});
});
highlight是core.css中定义的样式,你也可以改变它,注意这里有第二个function()这是hover方法的特点,请在API文档中查阅hover,上面也有例子说明
分享到:
相关推荐
Algorithm-Machine-Learning-for-Beginner-by-Python3.zip,斯克莱恩、坦索流。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
Beginner-Level COM Tutorial初学者COM指南
COCOS2d-X by Example Beginner-'s Guide
rails-beginner-s-guide是Rails 指导手册,帮组学习了解rails开发
CSES_PRACTICE-2021-Beginner-源码.rar
Emacs-Beginner-HOWTO.pdf, 学习emacs的入门手册,希望对emacs迷们有用
Hacking-Secret-Ciphers-with-Python-A-beginner-s-guide-to-cryptography-and-computer-programming-with-Python.pdf
资源分类:Python库 所属语言:Python 资源全名:for-beginner-piano-0.3.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Beginner-CPP-Programming-From-Beginner-to-Beyond
python_for_absolute_beginner-源码.rar
A list of beginner-friendly NLP projects—using pre-trained models,用预训练模型零基础体会最先进NLP技术,by Caleb Kaiser。
js-jquery-初学者项目 The Odin Project 的 Web 开发入门课程的练习
适合初学者的jquery的一个工程,在工程中学习是最好的方法了,希望对大家有帮助-Jquery for a beginner' s project in the projects is the best way to learn, and want to help you
NumPy_1_5_Beginner__039_s_Guide-234页
以pygame 游戏模块,来学习Python 基础,每章一个游戏。让python基础学得牢,学得有意思!
GeoServer Beginner's Guide offers you a practical introduction to GeoServer. Beginning with the installation and basic usage, you will learn to use the administration interface for adding data, ...
■Chapter 1: Introduction to Nginx Web Server ........................................................ 1 ■Chapter 2: Installing Nginx ....................................................................
C++Builder初学者很有用参考资料,内容非常详细。分为基础入门、快速提高、成功编程者三部分
godot engine to develop game 2d