工作常用

enter键操作

$(document).keypress(function(e){
if(e.keyCode==13 &&$("#hostNameVal").val()){
$('#hostQueryBtn').click();
e.preventDefault(); //防止事件冒泡传播。
//return false;

}else{

return ;
}
});

sessionStorage

sessionStorage.removeItem('totalCount');

sessionStorage.getItem('totalCount');

sessionStorage.setItem('totalCount');

sessionStorage.clear('totalCount');

 

jquery 常用选择器

$('#virtualList>.virTab+div~div')   ‘+号’后面第一个同辈元素  ‘~’后面所有同辈元素

$(this).next()  当前对象的下一个同辈元素

 $(this).nextAll()  查找当前元素之后所有的同辈元素

$(this).prevAll().filter(".currentPage")   查找当前元素之前所有的同辈元素,并且过滤拥有currentPage样式的

$(this).prev('span.upPage')  当前对象的上一个同辈元素

判断对象是否为空

$.isEmptyObject(data)

 

自定义属性设置与获取

var current=$(this).data('downpage');这个只能获取,不能设置

var current=$(this)[0].dataset.uppage 即可获取 亦可设置

datatables行创建回调

"fnCreatedRow": function(nRow, aData, iDataIndex) {
  $('td:eq(10)', nRow).addClass("details-control");
},

 

 

给元素身上保存JSON数据

var dataList=JSON.stringify(row);
console.log(dataList);
return '<span class="serverDetails" data-dataList=\''+dataList+'\' style="display:inline-block;cursor:pointer;color:#62d0e7;">查看详情</span>';

 

时间初始化

var now = $.now();

var lastTime = now - 3600000 * 24*30*12*4;// 最近3小时
//var nowDate = new Date(now).format("yyyy-MM-dd HH:mm:ss");
var nowDate = new Date(now).format("yyyy/MM/dd");
var lastDate = new Date(lastTime).format("yyyy/MM/dd");
var inittime = lastDate + " - " + nowDate;
$("#choiceTime").val(inittime);
$('#choiceTime').daterangepicker({
timePicker: true,
timePickerIncrement: 5,
timePicker12Hour: false,
format: 'YYYY/MM/DD'
//format: 'YYYY-MM-DD HH:mm:ss'
});

 

点击事件模板

$(document).on('click','#ioc_instance',function(e){



e.stopPropagation();
return false;
});

 

获取选中的复选框

 

var inputList = $('#operaTable input[type="checkbox"]:checked');

 

selecte使用时

 

<option value ="">请选择</option>
<option value ="ECS">ECS</option>

value的值要与内容一样  少写代码  技巧

 

 

select2

 

$("#applicationType").empty();
// $('#applicationType').append(str);

// var data = [{ id: 'enhancement', text: 'enhancement' }, { id: 'bug', text: 'bug' }, { id: 'duplicate', text: 'duplicate' }, { id: 'invalid', text: 'invalid' }, { id: 'wontfix', text: 'wontfix' }];
$("#applicationType").select2({
data: data,
placeholder:'请选择,多选',
allowClear:true,
theme: "classic",
width:230,
height:30,
tags:true,
multiple:true,
templateSelection:function(arg){

return arg.text;
//左用选择的在文本可见
},
templateResult:function(arg){
return arg.text;

}
// initSelection:function(){
// console.log('aa');
// }
});

 

取值时 var data= $("#applicationType").val();

posted @ 2017-05-16 11:04  教父123  阅读(150)  评论(0编辑  收藏  举报