Jquery摘要

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方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值