上源码
dataTable搜索function search(btn,grid)
dataTable重置
/**
* 公共js组件 @all
**/
var commonImgAddress = "/assets/global/img/default.jpg";
/**
*
*docName file组件的name
*viewId img的id
*localId div的id
* imgWidth img的宽度
* imgHeight img的高度
* divWidth div的宽度
* divHeight div的高度
*/
function setImagePreview(docName,viewId,localId,imgWidth,imgHeight,divWidth,divHeight,tip){
$('#uploadFiletIcon').text('');
var docObj=document.getElementById(docName);
var imgObjPreview=document.getElementById(viewId);
var fileObj=$('#'+docName).val();
if(tip==1){
$('#tip').val(1);
$('#uploadFileIconx').val('');
$('#uploadFileIcon').text('');
}else{
$('#iconTip').val(1);
}
if(fileObj){
if(docObj.files&&docObj.files[0]){
imgObjPreview.style.display='inline-block';
imgObjPreview.style.width=imgWidth;
imgObjPreview.style.height=imgHeight;
imgObjPreview.src=window.URL.createObjectURL(docObj.files[0]);
}else{
docObj.select();
var imgSrc=document.selection.createRange().text;
var localImagId=document.getElementById(localId);
localImagId.style.width=divWidth;
localImagId.style.height=divHeight;
try{
localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=imgSrc;
}catch(e){
alert("您上传的图片格式不正确,请重新选择!");
return false;
}
imgObjPreview.style.display='none';
document.selection.empty();
}
}
return true;
}
var extArray=new Array(".jpg",".jpeg",".png",".gif");
var zipArray=new Array(".zip",".rar");
/**
* 判断上传文件的类型
* @param file
* @param tip
* @returns {Boolean}
*/
function limitAttach(file,tip){
var finaFile="";
if(tip==1){
finaFile=extArray;
}else{
finaFile=zipArray;
}
var allowSubmit=false;
if(!file){
allowSubmit=true;
}
while(file.indexOf("\\")!= -1){
file=file.slice(file.indexOf("\\")+1);
}
var ext=file.slice(file.indexOf(".")).toLowerCase();
for(var i=0; i<finaFile.length; i++){
if(finaFile[i]==ext){
allowSubmit=true;
break;
}
}
if(!allowSubmit){
alert("只能上传以下格式的文件:"+(finaFile.join(""))+"\n 请重新选择再上传.");
return false;
}
return allowSubmit;
}
/**
* 全选 按钮
* @param th
* @param name
*/
function checkAllBox(th,name){
if(th){
if(th.checked){
if(name){
$("input[name='"+name+"']").attr("checked",true).parent('span').addClass('checked');
$(th).parent("span").addClass("checked");
}else{
$("input[name='checkBox']").attr("checked",true).parent('span').addClass('checked');
}
}else{
if(name){
$(th).parent("span").removeClass("checked");
$("input[name='"+name+"']").attr("checked",false).parent('span').removeClass('checked');
}else{
$("input[name='checkBox']").attr("checked",false).parent('span').removeClass('checked');
}
}
}
}
/**
* 格式化时间
* @param objDate 需要格式化的时间
* @returns clock 返回 2014-10-10 10:10:10
*/
function changeDate(objDate){
var clock="";
if(objDate!=null&&objDate){
var now=new Date(objDate);
var year=now.getFullYear();
var month=now.getMonth()+1;
var day=now.getDate();
var hh=now.getHours();
var mm=now.getMinutes();
clock=year+"-";
if(month<10)
clock+="0";
clock+=month+"-";
if(day<10)
clock+="0";
clock+=day+" ";
if(hh<10)
clock+="0";
clock+=hh+":";
if(mm<10) clock+='0';
clock+=mm;
if(now.getSeconds()<10){
clock+=":0"+now.getSeconds();
}else{
clock+=":"+now.getSeconds();
}
}
return clock;
}
/**
* 根据格式来格式化时间
* @param format 格式化时间的格式 如 yyyy-MM-dd
* @returns 返回 格式化后时间
*/
Date.prototype.format=function(format){
var o={
"M+":this.getMonth()+1,
"d+":this.getDate(),
"h+":this.getHours(),
"m+":this.getMinutes(),
"s+":this.getSeconds(),
"q+":Math.floor((this.getMonth()+3)/3),
"S":this.getMilliseconds()
}
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length));
for(var k in o)if(new RegExp("("+k+")").test(format))
format=format.replace(RegExp.$1,RegExp.$1.length==1?o[k]:("00"+o[k]).substr((""+o[k]).length));
return format;
}
function alertHint(msg,callback){
if(!msg){
msg="操作成功.";
}
bootbox.alert(msg);
setTimeout(function(){
bootbox.hideAll();
if(callback){
callback();
}
},2000);
}
/**
* 拼接字符串信息
* @param num
* @returns {Number}
*/
function factorial(obj,tip){
var finstring;
if(obj){
if(obj.length<=tip){
finstring=obj;
}else{
var temp=arguments.callee((obj.substring(tip,obj.length)),tip);
finstring+=obj.substring(0,tip)+"</br>"+temp
}
}
return finstring.replace("undefined","");
}
/**
* 获取 http://localhost:8080
*/
function getURL(projoName){
var curWwwPath=window.document.location.href;
var pathName=window.document.location.pathname;
var pos=curWwwPath.indexOf(pathName);
var localhostPaht=curWwwPath.substring(0,pos);
var finalName ;
if(projoName){
finalName = localhostPaht+projoName;
}else{
finalName=localhostPaht;
}
return finalName;
}
/**
* 获取上传文件的名字
* @param obj
* @param id
*/
function getFullPath(obj,id){
if(obj){
var path=obj.value;
var index=path.lastIndexOf("\\")+1;
if(index>0){
$('#'+id).html(path.substr(index));
}else{
$('#'+id).html(path);
}
}
}
function search(btn,grid){
var search_div=$(btn).parent().parent("div");
var inputs=search_div.find('input').filter(".form-filter");
for(var i=0;i<inputs.length;i++){
$(inputs[i]).val($(inputs[i]).val().trim());
}
grid.search(search_div);
}
function reset(btn,excludes,grid){
var search_div=$(btn).parent().parent("div");
grid.reset(search_div,excludes);
}
案例
<div id="data_table_search">
<label style="margin-left: 10px;">
编号:
<input type="text" class="form-filter input-sm" style="width: 120px;"
name="search_LIKE_contractCode">
</label>
<label style="margin-left: 10px;">
产品:
<input type="text" class="form-filter input-sm" style="width: 120px;" placeholder="产品"
name="search_LIKE_proName">
</label>
<label style="margin-left: 10px;">
状态:
<select name="search_AND_isreturn" id="isreturn" class="form-filter">
<option value="">所有</option>
<option value="N">待归还</option>
<option value="Y">已归还</option>
</select>
</label>
<label style="margin-left: 10px;">
超期:
<select name="search_AND_overdue" id="overdue" class="form-filter">
<option value="">所有</option>
<option value="Y">是</option>
<option value="N">否</option>
</select>
</label>
<label style="margin-left: 10px;">
<button class="btn btn-sm yellow margin-bottom filter-submit" value="搜索"
onclick="search(this,grid)"><i class="fa fa-search"></i> 搜索
</button>
<button class="btn btn-sm red filter-cancel" id="restSearch" onclick="reset(this,[],grid)"><i
class="fa fa-times"></i> 重置
</button>
</label>
</div>