- .on( events [, selector ] [, data ], handler )
事件委托,在3.0版本中,使用 on 来绑定事件,对于使用 js 添加到页面中的元素,需要使用下面的写法。
$( "#dataTable tbody" ).on( "click", "tr", function() {
console.log( $( this ).text() );
});
编码一系列 form 元素生成拼接字符串提交给后台使用
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
console.log( $( this ).serialize() );
});
//生成拼接字符串
single=Single&multiple=Multiple&multiple=Multiple3&check=check1
编码 form 元素生成包含键 name 和 value 的数组
$( "form" ).submit(function( event ) {
console.log( $( this ).serializeArray() );
event.preventDefault();
});
//生成数组
[
{
name: "a",
value: "1"
},
{
name: "b",
value: "2"
}
]
将数组、对象转化为 URL 传输需要的格式
traditional 为 boolean 值,true 为浅转化
$.param({ a: [ 2, 3, 4 ] }); // "a=2&a=3&a=4"
var myObject = {
a: {
one: 1,
two: 2,
three: 3
},
b: [ 1, 2, 3 ]
};
var recursiveEncoded = $.param( myObject );
//a%5Bone%5D=1&a%5Btwo%5D=2&a%5Bthree%5D=3&b%5B%5D=1&b%5B%5D=2&b%5B%5D=3
var shallowEncoded = $.param( myObject, true );
//a=%5Bobject+Object%5D&b=1&b=2&b=3
$( "#feeds" ).load( "feeds.php", { limit: 25 }, function() {
alert( "The last 25 entries in the feed have been loaded" );
});
$.ajax({
method: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
cache (default: true, false for dataType 'script' and 'jsonp') Type: Boolean
async (default: true) Type: Boolean 跨域请求和 dataType: "jsonp" 请求不支持同步操作.
crossDomain (default: false 同域名下, true 跨域请求) Type: Boolean
data Type: PlainObject or String or Array
"jsonp": Loads in a JSON block using JSONP.
在你的 URL 结尾添加 "?callback=?" 作为明确的返回函数.
<script type="application/javascript"
src="http://server.example.com/Users/1234?callback=parseResponse">
</script>
parseResponse({"Name": "Foo", "Id": 1234, "Rank": 7});
- .queue( [queueName ] )
显示或操纵 function 队列的执行
$( "#start" ).click(function() {
$( "div" )
.show( "slow" )
.animate({ left: "+=200" }, 5000 )
.queue(function() {
$( this ).addClass( "newcolor" ).dequeue();
})
.animate({ left: '-=200' }, 1500 )
.queue(function() {
$( this ).removeClass( "newcolor" ).dequeue();
})
.slideUp();
});
$( "#stop" ).click(function() {
$( "div" )
.queue( "fx", [] )
.stop();
});
- .dequeue( [queueName ] )
执行队列中的下一个function - jQuery.extend( target [, object1 ] [, objectN ] )
$.extend({}, object1, object2);
