removeData([name|list]),在元素上移除存放的数据,与$(...).data(name, value)函数作用相反
描述:
//从元素中删除之前添加的数据:
$("#btn2").click(function(){
$("div").removeData("greeting");
alert("Greeting is: " + $("div").data("greeting"));
});
on()方法替换bind()/live()/delegate()。
on()只是比bind()多了一个可选的'selector'参数,
替换live()写法:
//live()写法
$('#list li').live('click', '#list li', function() {
//function code here.
});
//on()写法
$(document).on('click', '#list li', function() {
//function code here.
});
替换delegate()写法:
//delegate()写法
$('#list').delegate('li', 'click', function() {
//function code here.
});
//on()写法
$('#list').on('click', 'li', function() {
//function code here.
});
0ff()函数主要用于解除由on()函数绑定的事件处理函数。
(1) 返回css属性
用法一:
jQueryObject.off( [ events [, selector ] [, handler ] ] )
用法二:
jQueryObject.off( eventsMap [, selector ] )
stop([clearQueue],[jumpToEnd]),停止所有在指定元素上正在运行的动画。
如果队列中有等待执行的动画(并且clearQueue没有设为true),他们将被马上执行
描述:
//停止当前正在运行的动画:
$("#stop").click(function(){
$("#box").stop();
});
描述:
//点击Go之后开始动画,点Stop之后会在当前位置停下来
// 开始动画
$("#go").click(function(){
$(".block").animate({left: '+200px'}, 5000);
});
// 当点击按钮后停止动画
$("#stop").click(function(){
$(".block").stop();
});
jQuery.isNumeric(value),确定它的参数是否是一个数字。
描述:
//Sample return values of $.isNumeric with various inputs.
$.isNumeric("-10"); // true
$.isNumeric(16); // true
$.isNumeric(0xFF); // true
$.isNumeric("0xFF"); // true
$.isNumeric("8e5"); // true (exponential notation string)
$.isNumeric(3.1415); // true
$.isNumeric(+10); // true
$.isNumeric(0144); // true (octal integer literal)
$.isNumeric(""); // false
$.isNumeric({}); // false (empty object)
$.isNumeric(NaN); // false
$.isNumeric(null); // false
$.isNumeric(true); // false
$.isNumeric(Infinity); // false
$.isNumeric(undefined); // false
deferred.pipe([doneFilter],[failFilter],[progressFilter]),筛选器和/或链Deferreds的实用程序方法。
描述:
//过滤解决值:
var defer = $.Deferred(),
filtered = defer.pipe(function( value ) {
return value * 2;
});
defer.resolve( 5 );
filtered.done(function( value ) {
alert( "Value is ( 2*5 = ) 10: " + value );
});
描述:
//过滤器拒值:
var defer = $.Deferred(),
filtered = defer.pipe( null, function( value ) {
return value * 3;
});
defer.reject( 6 );
filtered.fail(function( value ) {
alert( "Value is ( 3*6 = ) 18: " + value );
});;
描述:
//链任务:
var request = $.ajax( url, { dataType: "json" } ),
chained = request.pipe(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
deferred.notify(args),调用一个给定args的递延对象上的进行中的回调 (progressCallbacks)
通常情况下,只有一个递延的创建者,应调用此方法;你可以防止其他代码改变Deferred的状态或者通过deferred.promise()返回一个受限制的承诺对象报告状态
参数:
//args 可选参数传递到进行中的回调(progressCallbacks)
deferred.notifyWith(context,[args]),去掉字符串起始和结尾的空格。
参数:
//context 上下文传递progressCallbacks此对象。 //args 可选参数传递到progressCallbacks。
deferred.progress(progressCallbacks),当Deferred对象时生成进度通知时添加被访问处理程序。
参数:
//progressCallbacks 一个函数或函数数组,被呼叫递延生成进度通知。
deferred.state(),确定一个Deferred对象的当前状态。
deferred.state()方法返回一个字符串,代表Deferred对象的当前状态。 Deferred对象可以在三种状态之一:
描述:
//pending: Deferred对象是尚未完成状态 (不是 "rejected" 或 "resolved"). //resolved: Deferred对象是在解决状态 //rejected: Deferred对象是在被拒绝的状态
callbacks.add(callbacks),回调列表中添加一个回调或回调的集合。
描述:
//使用 callbacks.add() 添加新的回调到回调列表:
// a sample logging function to be added to a callbacks list
var foo = function( value ){
console.log( 'foo:' + value );
}
// another function to also be added to the list
var bar = function( value ){
console.log( 'bar:' + value );
}
var callbacks = $.Callbacks();
// add the function 'foo' to the list
callbacks.add( foo );
// fire the items on the list
callbacks.fire( 'hello' );
// outputs: 'foo: hello'
// add the function 'bar' to the list
callbacks.add( bar );
// fire the items on the list again
callbacks.fire( 'world' );
// outputs:
// 'foo: world'
// 'bar: world'
callbacks.disable(),禁用回调列表中的回调
描述:
//使用 callbacks.disable() 禁用回调列表:
// a sample logging function to be added to a callbacks list
var foo = function( value ){
console.log( value );
}
var callbacks = $.Callbacks();
// add the above function to the list
callbacks.add( foo );
// fire the items on the list
callbacks.fire( 'foo' ); // outputs: foo
// disable further calls being possible
callbacks.disable();
// attempt to fire with 'foobar' as an argument
callbacks.fire( 'foobar' ); // foobar isn't output
callbacks.empty(),从列表中删除所有的回调.
描述:
//使用 callbacks.empty() 清空回调列表:
// a sample logging function to be added to a callbacks list
var foo = function( value1, value2 ){
console.log( 'foo:' + value1 + ',' + value2 );
}
// another function to also be added to the list
var bar = function( value1, value2 ){
console.log( 'bar:' + value1 + ',' + value2 );
}
var callbacks = $.Callbacks();
// add the two functions
callbacks.add( foo );
callbacks.add( bar );
// empty the callbacks list
callbacks.empty();
// check to ensure all callbacks have been removed
console.log( callbacks.has( foo ) ); // false
console.log( callbacks.has( bar ) ); // false
callbacks.fire(arguments),禁用回调列表中的回调
描述:
//使用 callbacks.fire() 用任何已传递的参数调用列表中的回调:
// a sample logging function to be added to a callbacks list
var foo = function( value ){
console.log( 'foo:' + value );
}
var callbacks = $.Callbacks();
// add the function 'foo' to the list
callbacks.add( foo );
// fire the items on the list
callbacks.fire( 'hello' ); // outputs: 'foo: hello'
callbacks.fire( 'world '); // outputs: 'foo: world'
// add another function to the list
var bar = function( value ){
console.log( 'bar:' + value );
}
// add this function to the list
callbacks.add( bar );
// fire the items on the list again
callbacks.fire( 'hello again' );
// outputs:
// 'foo: hello again'
// 'bar: hello again'
callbacks.fired(),确定如果回调至少已经调用一次。
描述:
//使用callbacks.fired() 确定,如果列表中的回调至少有一次被呼叫
// a sample logging function to be added to a callbacks list
var foo = function( value ){
console.log( 'foo:' + value );
}
var callbacks = $.Callbacks();
// add the function 'foo' to the list
callbacks.add( foo );
// fire the items on the list
callbacks.fire( 'hello' ); // outputs: 'foo: hello'
callbacks.fire( 'world '); // outputs: 'foo: world'
// test to establish if the callbacks have been called
console.log( callbacks.fired() );
callbacks.fireWith([context][,args]),禁用回调列表中的回调
描述:
//使用 callbacks.fireWith() 访问给定的上下文和参数列表中的所有回调。
// a sample logging function to be added to a callbacks list
var log = function( value1, value2 ){
console.log( 'Received:' + value1 + ',' + value2 );
}
var callbacks = $.Callbacks();
// add the log method to the callbacks list
callbacks.add( log );
// fire the callbacks on the list using the context 'window'
// and an arguments array
callbacks.fireWith( window, ['foo','bar']);
// outputs: Received: foo, bar
callbacks.has(callback),确定是否提供的回调列表
描述:
//用 callbacks.has() 检查是否回调列表中包含一个特定的回调:
// a sample logging function to be added to a callbacks list
var foo = function( value1, value2 ){
console.log( 'Received:' + value1 + ',' + value2 );
}
// a second function which will not be added to the list
var bar = function( value1, value2 ){
console.log( 'foobar');
}
var callbacks = $.Callbacks();
// add the log method to the callbacks list
callbacks.add( foo );
// determine which callbacks are in the list
console.log( callbacks.has( foo ) ); // true
console.log( callbacks.has( bar ) ); // false
callbacks.lock(),锁定在其当前状态的回调列表。
描述:
//用 callbacks.lock()锁定一个回调列表,以避免进一步的修改列表状态 :
// a sample logging function to be added to a callbacks list
var foo = function( value ){
console.log( 'foo:' + value);
}
var callbacks = $.Callbacks();
// add the logging function to the callback list
callbacks.add( foo );
// fire the items on the list, passing an argument
callbacks.fire( 'hello' );
// outputs 'foo: hello'
// lock the callbacks list
callbacks.lock();
// try firing the items again
callbacks.fire( 'world' );
// as the list was locked, no items
// were called so 'world' isn't logged
callbacks.locked(),确定是否已被锁定的回调列表。
描述:
//用 callbacks.locked() 确定是否已被锁定的回调列表:
// a sample logging function to be added to a callbacks list
var foo = function( value ){
console.log( 'foo:' + value);
}
var callbacks = $.Callbacks();
// add the logging function to the callback list
callbacks.add( foo );
// fire the items on the list, passing an argument
callbacks.fire( 'hello' );
// outputs 'foo: hello'
// lock the callbacks list
callbacks.lock();
// test the lock-state of the list
console.log ( callbacks.locked() ); //true
callbacks.remove(callbacks),删除回调或回调回调列表的集合。
描述:
//用callbacks.remove() 删除回调或回调回调列表的集合。
// a sample logging function to be added to a callbacks list
var foo = function( value ){
console.log( 'foo:' + value );
}
var callbacks = $.Callbacks();
// add the function 'foo' to the list
callbacks.add( foo );
// fire the items on the list
callbacks.fire( 'hello' ); // outputs: 'foo: hello'
// remove 'foo' from the callback list
callbacks.remove( foo );
// fire the items on the list again
callbacks.fire( 'world' );
// nothing output as 'foo' is no longer in the list/code>
jQuery.callbacks(flags),一个多用途的回调列表对象,提供了强大的的方式来管理回调函数列表。
$.Callbacks()的内部提供了jQuery的$.ajax() 和 $.Deferred() 基本功能组件。它可以用来作为类似基础定义的新组件的功能。
描述:
//以下是两个样品的方法命名fn1 and fn2:
function fn1( value ){
console.log( value );
}
function fn2( value ){
fn1("fn2 says:" + value);
return false;
}
//这些可以添加为回调函数作为一个$.Callbacks的列表,并调用如下:
var callbacks = $.Callbacks();
callbacks.add( fn1 );
callbacks.fire( "foo!" ); // outputs: foo!
callbacks.add( fn2 );
callbacks.fire( "bar!" ); // outputs: bar!, fn2 says: bar!
//这样做的结果是,它使构造复杂的回调列表变得简单,输入值可以通过尽可能多的函数根据需要轻松使用。
//用于以上的两个具体的方法: .add() 和 .fire() .add() 支持添加新的回调回调列表, 而.fire() 提供了一种用于处理在同一列表中的回调方法的途径.
//另一种方法由$.Callbacks 的remove(),用于从回调列表中删除一个特定的回调。下面是.remove() 使用的一个例子:
var callbacks = $.Callbacks();
callbacks.add( fn1 );
callbacks.fire( "foo!" ); // outputs: foo!
callbacks.add( fn2 );
callbacks.fire( "bar!" ); // outputs: bar!, fn2 says: bar!
callbacks.remove(fn2);
callbacks.fire( "foobar" );
// only outputs foobar, as fn2 has been removed.