Jquery摘要
2016-01-04 10:46
633 查看
1 绑定事件传递参数
$("#Android_Jump_Content").bind('click', 'Android', display_jump_content)
不能直接在函数后面添加参数,否则表示函数调用,函数调用的结果绑定在click事件上
$("#Android_Jump_Content").bind('click', display_jump_content('Android'))
2 判断元素是否存在
var table = $("#to_add_jump_table")
if (table == undefined || null == table || table.length == 0){
//元素不存在
}
3 在事件方法中,根据事件对象获取
$("#to_add_jump_table .glyphicon-remove").on('click', function () {
console.log('remove record')
var record = $(this).parent().parent()
record.remove()
//$("#to_add_jump_table").removeChild(record)
})
需要用$(this),把事件对象转化为jquery对象
4 ajax error方法,当响应码为204,则也会进入到error方法。
(如果服务端响应码为200,但是没有响应体,则ajax做视为204处理)
$.ajax({
type: "GET",
url: "/jump/xx",
data: {"type": osType},
dataType: "json",
async: true,
success: function (data) {
console.log('success to deploy')
display_jump_content(event)
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('fails to deploy')
console.log(XMLHttpRequest.readyState + XMLHttpRequest.status + XMLHttpRequest.responseText)
handle_jump(null)
}
});
说明,和参数 dataType: "json" 有关,如果没有设置 dataType: "json",则没有响应体时,则进入到success方法
$("#Android_Jump_Content").bind('click', 'Android', display_jump_content)
不能直接在函数后面添加参数,否则表示函数调用,函数调用的结果绑定在click事件上
$("#Android_Jump_Content").bind('click', display_jump_content('Android'))
2 判断元素是否存在
var table = $("#to_add_jump_table")
if (table == undefined || null == table || table.length == 0){
//元素不存在
}
3 在事件方法中,根据事件对象获取
$("#to_add_jump_table .glyphicon-remove").on('click', function () {
console.log('remove record')
var record = $(this).parent().parent()
record.remove()
//$("#to_add_jump_table").removeChild(record)
})
需要用$(this),把事件对象转化为jquery对象
4 ajax error方法,当响应码为204,则也会进入到error方法。
(如果服务端响应码为200,但是没有响应体,则ajax做视为204处理)
$.ajax({
type: "GET",
url: "/jump/xx",
data: {"type": osType},
dataType: "json",
async: true,
success: function (data) {
console.log('success to deploy')
display_jump_content(event)
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('fails to deploy')
console.log(XMLHttpRequest.readyState + XMLHttpRequest.status + XMLHttpRequest.responseText)
handle_jump(null)
}
});
说明,和参数 dataType: "json" 有关,如果没有设置 dataType: "json",则没有响应体时,则进入到success方法
相关文章推荐
- jquery之$()函数
- 用户界面框架jQuery EasyUI示例大全之Tabs
- jQuery中prop和attr的区别
- jquery 实现table行交换:上移/下移
- jquery对象和dom对象的区别
- jquery使用jsonp进行跨域调用
- 跨域请求之jQuery的ajax jsonp的使用
- jquery事件重复绑定解决办法
- jquery禁用右键功能和f5刷新
- jQuery对象与DOM对象之间的转换方法
- jquery的事件绑定与解绑定-on
- jquery禁用某些字段
- jQuery数据缓存$.data
- 浅谈 jQuery 核心架构设计
- jQuery实现简单的点赞效果
- jQuery EasyUI之DataGrid使用实例详解
- 实例详解jQuery结合GridView控件的使用方法
- jQuery自动完成插件completer附源码下载
- jQuery插件之jQuery.Form.js用法实例分析(附demo示例源码)
- jquery中cookie用法实例详解(获取,存储,删除等)