jQuery(document).ready(function(){ console.log("hello world 页面文档加载结束"); }); write less do more;
var $$ = jQuery; $$(document).ready(function(){ console.log("hello world 页面文档加载结束"); });
(function($){ $(document).ready(function(){ console.log("hello world 页面文档加载结束"); }); })(jQuery);
$(function(){ console.log("hello world 页面文档加载结束"); })
$box.css({ width : "100px", height : 100, marginLeft : "+=200", backgroundColor : "yellowgreen" }) $box.css({ marginLeft : "+=100" })
var $boxs = $(".box"); // jQuery实例对象里面的所有方法都是对DOM对象的批量操作; $boxs.css({ width : function( index , value ){ return (index + 1) * 100 }, height : 100, margin : 5, backgroundColor : function( index , value ){ return value.replace(/\d/g, (index + 1) * 20); } }) console.log($boxs);
$("#box,.box,.list *").css({
width : function( index , value ){
return (index + 1) * 100
},
height : 100,
margin : 5,
backgroundColor : function( index , value ){
return value.replace(/\d/g, (index + 1) * 20);
}
});
jQuery关系选择库:如直接子集选择器 selector>children :
$(".box>div").css({
background : "#fff"
})
$(".son").parent() 返回值就是son的父级元素,如果不加上一个限制条件的话会一直向外寻找父级,直到html
$(".son").parent().css({
background : "skyblue"
})
// $(".son").parents(".box").css({
// borderWidth : 10
// })
// parentsUtil
$(".son").parentsUntil(".box").css({
borderWidth : 10
})
$(".box").mouseover(function(){
$(this)
.stop(true)
.animate({
width : 1380
})
.siblings(".box")
.stop(true)
.animate({
width : 0
})
.end()
.children(".content")
.css({
left : 0
})
})
$(".box").mouseout(function(){
$(".box")
.stop(true)
.animate({
width : 345
})
.queue(function(){
$(this)
.children(".content")
.css({
left : 345
})
})
})
原文:https://www.cnblogs.com/SeventhMeteor/p/14764623.html