juery可以动态地在一个元素上加上键值对,其中“对”甚至可以是对象
$('#data').data('test',{name:'yuchao',age:24});
alert($('#data').data('test').age);
$('#data').removeData('test');
alert($('#data').data('test'));
<div id="data"></div>
<div id="data"></div>
queue(name,callback)
在匹配的元素的队列最后添加一个函数
Adds a new function, to be executed, onto the end of the queue of all matched elements.
返回值
jQuery
参数
name (String) :队列名,默认为fx
callback (Function) : 要添加进队列的函数
示例
插入一个自定义函数 如果函数执行后要继续队列,则执行 jQuery(this).dequeue();
HTML 代码:
<style> div { margin:3px; width:40px; height:40px; position:absolute; left:0px; top:30px; background:green; display:none; } div.newcolor { background:blue; } </style> Click here... <div></div>
jQuery 代码:
$(document.body).click(function () { $("div").show("slow"); $("div").animate({left:'+=200'},2000); $("div").queue(function () { $(this).addClass("newcolor"); $(this).dequeue(); }); $("div").animate({left:'-=200'},500); $("div").queue(function () { $(this).removeClass("newcolor"); $(this).dequeue(); }); $("div").slideUp(); });
queue(name,queue)
将匹配元素的队列用新的一个队列来代替(函数数组).
dequeue([name])
从队列最前端移除一个队列函数,并执行他。
Removes a queued function from the front of the queue and executes it.
返回值
jQuery
参数
name (String) :队列名,默认为fx
示例
用dequeue来结束自定义队列函数,并让队列继续进行下去。
HTML 代码:
<style> div { margin:3px; width:50px; position:absolute; height:50px; left:10px; top:30px; background-color:yellow; } div.red { background-color:red; } </style> <button>Start</button> <div></div>
jQuery 代码:
$("button").click(function () { $("div").animate({left:'+=200px'}, 2000); $("div").animate({top:'0px'}, 600); $("div").queue(function () { $(this).toggleClass("red"); $(this).dequeue(); }); $("div").animate({left:'10px', top:'30px'}, 700); });