Javascript & JQuery常用操作备忘

  • ajax_1

方式一

$.ajax({
    type: 'POST',
    url : '/show-choose-edit',
    data: JSON.stringify(map),
    async : true,
    timeout : 15000,
    contentType : "application/json; charset=utf-8",
    dataType: 'json',
    success: function (data) {
       
    },
    error: function(e){
        
    }
})

方式二

$.ajax({
    url : '/setDivinerConfig',
    type : "POST",
    contentType : "application/json; charset=utf-8",
    dataType : "json",
    async : true,
    timeout : 180000,
    data : JSON.stringify(logTpl),
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        
    }
}).done(function(data, textStatus, jqXHR) {
    if (data.status == 'ok') {
       
    }else if(data.status == 'nopermission'){
        
    } else {
        
    }
});

  • setTimeout

setTimeout(function(){ window.location.href='/edit-diviner-config/' + p_conf['placementId']; },6000)
  • 使用JS数组

var arr = new Array();
arr.push();
for(var index in arr){
    alert(arr[index]);
}
  • 触发器trigger

('#btnSave').trigger("click");
  • 按钮disable

.addClass('disabled');
.removeClass('disable');
  • 相同.class的each遍历

$("#inputId" ).keyup(function(){
    var val = $(this).val();
    $('.edit-pid-class' ).each(function(){
	if($(this).html( ) == val){
	    var a = "#myTab a[href='#di-placement-"+val+"']";
	    $(a).trigger("click");
	}
	if($(this).html().indexOf(val) == 0){
	    $(this ).show();
	}else{
	    $(this ).hide();
	}
    });
});
  • center():让提示信息显示在中间

jQuery.fn.center = function () {
    this.css('position','absolute');
    this.css('top', ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + 'px');
    this.css('left', ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + 'px');
    return this;
}


  • 按钮disable


转载于:https://my.oschina.net/supersonic/blog/386094

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值