// 居中 $(window).resize(function(){ $('.n-format').css({ position:'absolute', left: ($(window).width() - $('.n-notice').outerWidth())/2, top: ($(window).height() - $('.n-notice').outerHeight())/2 + $(document).scrollTop() }); }); $(window).resize(); // 拖动 $('.n-format').mousedown( function (event) { var isMove = true; var abs_x = event.pageX - $('.n-format').offset().left; var abs_y = event.pageY - $('.n-format').offset().top; $(document).mousemove(function (event) { if (isMove) { var obj = $('.n-format'); obj.css({'left':event.pageX - abs_x, 'top':event.pageY - abs_y}); } } ).mouseup( function () { isMove = false; } ); } );
// 避免多次执行 $("#ok").unbind("click").bind("click",function(){}
$("#tableid tr:eq(1) td:last a").hide() // <table id="tableid"> 选择table的第二行的最后一个单元格中的a标签
$("#table2 tr:gt(1) td:nth-child(4)") // 获得表格从第二行开始的第四列
获得table的行数。
$("#tableid")[0].rows.length
获得表格的列数
$("#tosql")[0].rows.item(0).cells.length
出现
问题的解决办法
document.onkeydown=function(event){ var e = event || window.event || arguments.callee.caller.arguments[0]; if(e && e.keyCode==13){ // enter 键 addNewRow(); } if(e && e.keyCode==9){ //tab 键 $("#clear").click(); } };
判断div是否隐藏
$("#divID").is(":hidden"); //是否隐藏
$("#divID").is(":visible"); //是否可见
function numcheck() { // 只能输入数字 if (event.keyCode < 48 || event.keyCode > 57) { event.returnValue = false; } }
补齐位数
Number.prototype.Left3=function(){ if(this.toString().length>3)return this.toString().substr(0,3); else{ var str=this.toString(); for(var i=0;i<=3-str.length;i++)str="0"+str; return str; } }
获取url中的参数方法
function getParameter (sProp){ var re = new RegExp (sProp + "=([^&]*)" , "i" ); var a = re . exec (document . location . search ); return a == null ? null:a [ 1 ]; }
转换参数乱码
decodeURI()
ligergrid表格添加tab事件和enter事件
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <link href="plugins/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css"> <script src="js/jquery-1.7.2.js" type="text/javascript"></script> <script src="js/core/base.js" type="text/javascript"></script> <!-- <script src="js/ligerui.min.js" type="text/javascript"></script> --> <!-- <script src="js/plugins/ligerTree.js" type="text/javascript"></script> --> <script src="plugins/json/json2.js" type="text/javascript"></script> <script src="plugins/ligerUI/js/core/base.js" type="text/javascript"></script> <script src="plugins/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script> <script src="plugins/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script> <script src="plugins/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script> <script src="plugins/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script> <script src="plugins/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script> <script src="plugins/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script> <%if(session.getAttribute("employ")==null){%> <script type="text/javascript"> window.parent.location.href="Login.jsp"; </script> <% return;} %> <%-- <%@include file="head.jsp"%> --%> <script type="text/javascript"> var parent = window.location.href.split("&")[0].split("=")[1]; var parm = window.location.href.split("&")[1].split("=")[1]; var flag=false; var indexCount=1; var rowCount=0; var colCount=0; var product={}; $(function() { //$('.l-grid-loading').show(); $.ajax({ url:"DetailList", dataType:"json", type:"POST", data:{ "parent":parent, "parm":parm }, async: true, cache: false, success:function(json){ if(json.length == 0){ product.Rows=[]; }else{ product.Rows=json.details; } $('.l-grid-loading').hide(); f_initGrid(); $("#add").show(); $("#delete").show(); $("#submit").show(); f_success(); }, beforeSend :function(){ } }) }) ; var manager, g; function f_initGrid() { g = manager = $("#maingrid").ligerGrid({ columns: [ { display: 'a', align:'center',name: 'komoku', 90, type: 'int', editor:{type: 'int'}, render: getValue }, { display: 'b', align:'center', name: 'komokuName',200, editor: { type: 'text' }, render: getValue }, { display: 'c', align:'center', name: 'number',80, editor: { type: 'text' }, render: getValue }, { display: 'd', align:'center', name: 'remark',300, editor: { type: 'text' }, render: getValue } ], onSelectRow: function (rowdata, rowindex) { $("#txtrowindex").val(rowindex); }, dataAction: 'local', /* rownumbers:true, */ enabledSort: false, enabledEdit: true, clickToEdit: true, checkbox:false, usePager :false, allowHideColumn: false, allowUnSelectRow: true, onBeforeSubmitEdit: f_onBeforeSubmitEdit, onBeforeEdit: f_onAfterEdit, onAfterAddRow:f_onAfterAddRow, 718, height:"88%", data:product }); } function getValue(r, c, v, i) { if(v==""||!v){ v="_"; return "_"; }else{ return v; } } function f_onBeforeSubmitEdit(e) { } function f_onAfterEdit(e) { rowCount=e.rowindex; colCount=e.column.columnindex; if (e.column.name=="number" || e.column.name=="remark" ) { flag=true; } } // 添加行时 function f_onAfterAddRow(e) { } // 初始第一行 function f_success() { var len = manager.rows.length; if(len == 0){ manager.addRow({ komoku:"001", komokuName:"_", number:"_", remark:"_" }); } } // 补齐 Number.prototype.Left3=function(){ if(this.toString().length>3)return this.toString().substr(0,3); else{ var str=this.toString(); for(var i=0;i<=3-str.length;i++)str="0"+str; return str; } } // 添加新行 function addNewRow() { var len = manager.rows.length; indexCount=indexCount+1; manager.addRow({ komoku:indexCount.Left3(), komokuName:"_", number:"_", remark:"_" }) var row = manager.getRow(len); // 把焦点放到最后一行 var gridTr=manager.getRowObj(len); manager._applyEditor($(gridTr).children()[1]); //滚动条置底 $(".l-grid-body").scrollTop($(".l-grid-body")[0].scrollHeight); } // 获得选中行 function getSelected() { $('.l-grid-loading').show(); var allRows = manager.getSelectedRows(); } // 获得所有数据 function getData() { if (manager.getRow(0)==null) { alert("添加行"); return ; } // 插入数据之前把空值替换成"_"; var data = manager.getData(); for (var i = 0; i < data.length; i++) { data[i].komoku=data[i].komoku==""?"_":data[i].komoku; data[i].komokuName=data[i].komokuName==""?"_":data[i].komokuName; data[i].number=data[i].number==""?"_":data[i].number; data[i].remark=data[i].remark==""?"_":data[i].remark; } $('#my > .l-grid-loading').html("登陆中..."); $('#my > .l-grid-loading').show(); var jsonData=JSON.stringify(data); $.ajax({ url:"makeDetailInfoAction", type:"post", dataType:"json", data:{ "filename":parm, "project":parent, "json":jsonData }, success:function (data){ $("#my > .l-grid-loading").hide(); if (data=="false") { alert("没有权限"); return; } if(data=="0"){ $.ligerDialog.success('登陆完成'); setInterval("location.reload();",1000); }else { } },error:function (){ // 返回值存在问题 } }); } // 删除行 function deleteRow() { if(manager.selected == ""){ //alert("请选择要删除的行") $.ligerDialog.warn('请选择要删除的行'); }else{ $.ligerDialog.confirm('删除吗', function (yes) { if(yes){ manager.deleteSelectedRow(); } }); }// end else } </script> </head> <body style="position:relative" id="my"> <div class="l-grid-loading" style="display: block;" id="load">正在添加</div> <!-- <div class="l-clear"></div> --> <div id="ZJ" style="position:absolute;float:right;margin-left:710px;margin-top: 2px;"> <input id="add" type="button" onclick="addNewRow()" value="添加" tabindex="-1" style=" 65px;height: 26px;display: none;margin-left: 22px;" /> </div> <div id="maingrid"></div> <br /> <input type="button" id="delete" class="xdCl" onclick="deleteRow()" value="删除" style=" 65px;height: 26px;display: none;" /> <input type="button" id="submit" class="xdCl" onclick="getData()" value="登陆" style=" 65px;height: 26px;display: none;margin-left: 657px;" /> <div id="clear" style="display:none;"> </div> <script type="text/javascript"> document.onkeydown=function(event){ var e = event || window.event || arguments.callee.caller.arguments[0]; if(e && e.keyCode==13){ // enter 键 $("#maingrid").click(); // 取消焦点 if (flag) { addNewRow(); flag=false; } }
if(e && e.keyCode==9){ //tab 键
var leng=manager.rows.length;
$("#maingrid").click();
if (rowCount<leng) {
var gridTr=manager.getRowObj(rowCount);
if (colCount<3) {
manager._applyEditor($(gridTr).children()[colCount+1]);
}else if(colCount==3){ // 焦点移到下一行
colCount=0;
rowCount=rowCount+1;
if (rowCount<leng) {
gridTr=manager.getRowObj(rowCount);
manager._applyEditor($(gridTr).children()[colCount]);
}
flag=false;
}
}
}
};
</script>
</body>
</html>