Repository navigation
Open
Description
Ajax:
$.ajax({
url:"json/test.json?_="+Math.random(),
type:"get",
dataType:"json",//"text"、"html"、"jsonp"...
success: function(data){
concole.log(data);
}
});
事件:
语法:
$("#box").on("click", function () {
});
例:
var $box = $("#box");
$box.on("click", function () {
console.log(1);//this:当前元素(JS原生对象) $(this)
});
$box.on("click", function () {
console.log(2);
});
$box.on("mouseover", function () {
console.log(3);
});
$box.on("mouseout", function () {
console.log(4);
});
工具:
jQuery.browser.version——略each——在jQuery中有两个each- 循环选择器获取到的jQuery集合中的每一项
$("div").each(function (index, item) {
console.log(item);
});
+ 循环数组、类数组、对象中的每一项
$.each([12,13,23], function (index, item) {
console.log(item);
});
$.each(document.getElementsByTagName("*"), function (index, item) {
console.log(item);
});
$.each({name: "yang", age: 7}, function (index, item) {
console.log(item);
});
$.makeArray——等价于listToArraymap——在jQuery中也有两个map,和each的原理一样,只是可以支持返回值
动画:
$("#box").animate({left:xxx,top:xxx,...},duration,"linear/swing",function (){});
stop——结束之前正在运行的动画,开启下一个新的动画delay——延迟finnsh
$("#box").stop().animate({...});
fadeIn——淡入fadeOut——淡出fadeToggle——showhidetoggleslideUpslideDownslideToggle
$(function () {
var $submit = $("#submit");
var $box = $("#box");
$submit.on("click", function () {
//$box.stop().hide(500);
//$box.stop().hide("slow");//"fast" 时间ms
//$box.stop().slideUp(500);
//$box.stop().fadeOut(500);
//$box.stop().delay(1000).slideToggle(500);
//$box.slideUp(500).stop().hide(500);
//stop的意思是:结束上一个动画,下一个动画是紧接着当前位置开始运动的
//$box.slideUp(500).finish().toggle(500);
//finish的意思是:结束上一个动画,并且让元素快速的到达目标位置,再开始下一个动画
//$box.stop().animate({
// stop:600
//},1000,"swing")
$box.stop().animate({
stop:600,
},1000, function () {
$(this).css("background", "#000")
});
})
});
Metadata
Metadata
Assignees
Labels
No labels
Activity