概述
/**
* Requirements:
* $Id: dbwtool.js,v 1.1 2010/06/26 13:03:55 yzy Exp $
*/
var _PAGE_SIZE = 10;
var dbwtool = new function () {
//*************************************************
// Constants
//*************************************************
this.datePattern = "yyyy-MM-dd HH:mm:ss";
// same as DATE_FORMAT_UUM
/**
* callDWR (uniform interface).
*
* @param target:
* indicates what to get. structure: {object: obj, method: method};
* @param params:
* array if parameter objects;
* @param cbGotData:
* callback function;
* @return
* data object (original).
*/
this.callDWR = function (target, params, cbGotData) {
if(!target || !target.object || !target.method) {
return null;
}
try {
if(typeof cbGotData != 'function') {
DWREngine.setAsync(false);
}
var returnData = null;
var code = target.object + "." + target.method + "(";
if(params && params.length) {
for(var i = 0; i < params.length; i++) {
code += "params[" + i + "], ";
}
}
code += "{"
+ "
callback: function(retData){"
+ "
returnData = retData;"
+ "
if(typeof cbGotData == 'function') {"
+ "
cbGotData(retData);"
+ "
}"
+ "
},"
+ "
errorHandler:function(errMsg, uumException) {"
+ "
if(typeof uumError == 'function') {"
+ "
uumError(errMsg, uumException);"
+ "
}"
+ "
}"
+ "})";
eval(code);
if(typeof cbGotData != 'function') {
DWREngine.setAsync(true);
}
return returnData;
} catch (e) {
alert("data.callDWR: " + e.message);
return null;
}
};
/**
* callDWRSync (uniform interface).
*
* @param target:
* indicates what to call. structure: DepartmentBean.getDepartmentDto;
* @param params:
* array if parameter objects;
* @return
* data object (original).
*/
this.callDWRSync = function (target, params) {
if(!target) return null;
try {
DWREngine.setAsync(false);
var returnData = null;
var code = target + "(";
if(params && params.length) {
for(var i = 0; i < params.length; i++) {
code += "params[" + i + "], ";
}
}
code += "{"
+ "
callback: function(retData){"
+ "
returnData = retData;"
+ "
},"
+ "
errorHandler:function(errMsg, uumException) {"
+ "
if(typeof uumError == 'function') {"
+ "
uumError(errMsg, uumException);"
+ "
}"
+ "
}"
+ "})";
eval(code);
return returnData;
} catch (e) {
alert("data.callDWRSync: " + e.message);
return null;
}
};
/**
* callDWRBusiness (uniform interface).
*
* @param target:
* indicates what to call. structure: DepartmentBean.getDepartmentDto;
* @param params:
* array if parameter objects;
* @return
* data object (original).
*/
this.callDWRBusiness = function (target, params) {
if(!target) return null;
try {
DWREngine.setAsync(false);
var returnData = null;
var code = target + "(";
if(params && params.length) {
for(var i = 0; i < params.length; i++) {
code += "params[" + i + "], ";
}
}
code += "{"
+ "
callback: function(retData){"
+ "
returnData = retData;"
+ "
},"
+ "
errorHandler:function(errMsg, dwrException) {"
/*+ "
if(typeof uumError == 'function') {"*/
+ "
returnData = dwrException;"
/*+ "
}"*/
+ "
}"
+ "})";
eval(code);
return returnData;
} catch (e) {
alert("data.callDWRBusiness: " + e.message);
return null;
}
};
/**
* callDWRAsync (uniform interface).
* the default is synchronous
*
* @param target:
* indicates what to call. structure: DepartmentBean.getDepartmentDto;
* @param params:
* array if parameter objects;
* @param cbGotData:
* callback function;
* @return
* data object (original).
*/
this.callDWRAsync = function (target, params, cbGotData) {
if(!target) return null;
try {
DWREngine.setAsync(true);
var code = target + "(";
if(params && params.length) {
for(var i = 0; i < params.length; i++) {
code += "params[" + i + "], ";
}
}
code += "{"
+ "
callback: function(retData){"
+ "
if(typeof cbGotData == 'function') {"
+ "
cbGotData(retData);"
+ "
}"
+ "
},"
+ "
errorHandler:function(errMsg, uumException) {"
+ "
if(typeof uumError == 'function') {"
+ "
uumError(errMsg, uumException);"
+ "
}"
+ "
}"
+ "})";
eval(code);
DWREngine.setAsync(false);
} catch (e) {
DWREngine.setAsync(false);
alert("data.callDWRAsync: " + e.message);
}
};
};
/*functions on table dynamic style*/
function styleTable2(){
//-隔行,滑动,点击 变色
$('.cssraindemo2 tbody tr:even').addClass('odd');
$('.cssraindemo2 tbody tr').hover(
function() {$(this).addClass('highlight');},
function() {$(this).removeClass('highlight');}
);
$('.cssraindemo2 tbody tr').click(
function() {$('.cssraindemo2 tbody tr').removeClass('selected');$(this).toggleClass('selected');}
);
};
function styleTable1(){
$('.cssraindemo2 tbody tr:even').addClass('odd');
$('.cssraindemo2 tbody tr').hover(
function() {$(this).addClass('highlight');},
function() {$(this).removeClass('highlight');}
);
// 如果复选框默认情况下是选择的,变色.
$('.cssraindemo2 input[type="checkbox"]:checked').parents('tr').addClass('selected');
// 复选框
$('.cssraindemo2 tbody tr').click(
function() {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
$(this).find('input[type="checkbox"]').removeAttr('checked');
} else {
$(this).addClass('selected');
$(this).find('input[type="checkbox"]').attr('checked','checked');
}
}
);
};
function styleTable3(){
$('.cssraindemo3 tbody tr:even').addClass('odd');
$('.cssraindemo3 tbody tr').hover(
function() {$(this).addClass('highlight');},
function() {$(this).removeClass('highlight');}
);
// 如果单选框默认情况下是选择的,变色.
$('.cssraindemo3 input[type="radio"]:checked').parents('tr').addClass('selected');
// 单选框
$('.cssraindemo3 tbody tr').click(
function() {
$(this).siblings().removeClass('selected');
$(this).addClass('selected');
$(this).find('input[type="radio"]').attr('checked','checked');
}
);
};
function validate(){
var isSubmit = true;
$(document).find('input[reg]').each(function(){
var thisReg = new RegExp($(this).attr('reg'));
if(!thisReg.test(this.value))
{
$(this).removeClass('tooltipinputok').addClass('tooltipinputerr');
isSubmit = false;
}
});
return isSubmit;
}
function clearValidate(classname){
$(classname).find('input').each(function(){
$(this).removeClass('tooltipinputok').removeClass('tooltipinputerr');
//$(this).val('');
});
}
function clearInput(classname){
$(classname).find('input').each(function(){
if($(this).attr('type')!='button')
$(this).val('');
});
$(classname).find('textarea').each(function(){
$(this).val('');
});
}
//显示对话框
function showModal(h,w){
var nh=h,nw=w;
var top=0,left=0;
top = document.body.clientHeight/2-nh/2;
left = document.body.clientWidth/2-nw/2;
$('#EditForm').attr("style","height:"+(nh)+"px;width:"+(nw+12)+"px;top:"+top+"px;left:"+left+"px;");
$('#EditForm').jqm({
modal: true,
overlay: 30, //0-100 (int) : 0 is off/transparent, 100 is opaque
toTop: false,//add for ie if set div overflow to auto
overlayClass: 'jqmOverlay'
}).jqDrag('#jqmTitle').jqmShow().jqResize('.jqResize');
}
function showModal1(form,h,w,index){
var nh=h,nw=w;
var top=0,left=0;
top = document.body.clientHeight/2-nh/2;//document.body.clientHeight/2-nh/2;
left = document.body.clientWidth/2-nw/2;
$(form).attr("style","height:"+(nh)+"px;width:"+(nw+12)+"px;top:"+top+"px;left:"+left+"px;");
$(form).css("z-index",index==null?3001:index);
$(form).jqm({
modal: true,
overlay: 30, //0-100 (int) : 0 is off/transparent, 100 is opaque
toTop: true,//add for ie if set div overflow to auto
overlayClass: 'jqmOverlay'
}).jqmAddClose('#closeForm').jqDrag('#jqmTitle').jqmShow();
}
//从字典表取数据填充下拉框
function fillType(input,type){
var dics = dbwtool.callDWRSync('DictionaryDWR.getDictionarysByType',[type]);
//console.log(dics);
if(dics){
for (var i=0;i<dics.length;i++){
$(input).append('<option value='+dics[i].dicId+'>'+dics[i].codeName+'</option>');
}
}
}
function fillOrg(org){
var orgs = dbwtool.callDWRSync('OrganizationDWR.getOrganizationTree',[accountDto.orgCode]);
if(orgs){
for (var i=0;i<orgs.length;i++){
var tabs="";
for(var j=0;j<orgs[i].level-1;j++){
tabs +=" ";
}
$(org).append('<option value='+orgs[i].code+'>'+tabs+orgs[i].name+'</option>');
}
}
}
function fillOrgId(org){
var orgs = dbwtool.callDWRSync('OrganizationDWR.getOrganizationTree',[accountDto.orgCode]);
if(orgs){
$(org).empty();
for (var i=0;i<orgs.length;i++){
var tabs="";
for(var j=0;j<orgs[i].level-1;j++){
tabs +=" ";
}
$(org).append('<option value='+orgs[i].orgId+'>'+tabs+orgs[i].name+'</option>');
}
}
}
function fillProvider(){
var providers = dbwtool.callDWRSync('ProviderDWR.getAllProviders');
$("#provider").append('<option value=0>全部</option>');
if(providers){
for (var i=0;i<providers.length;i++){
$("#provider").append('<option value='+providers[i].providerId+'>'+providers[i].name+'</option>');
$("#providerId").append('<option value='+providers[i].providerId+'>'+providers[i].name+'</option>');
}
}
}
function fillProduct(providerId,product,blank){
var id = providerId;
if(id == 0) id=null;
var products = dbwtool.callDWRSync('ProductDWR.getProductsByProviderId',[id]);
$(product).empty();
if(blank) $(product).append('<option value=0>全部</option>');
if(products){
if(products[0])$('#unit').val(products[0].unit);
for (var i=0;i<products.length;i++){
$(product).append('<option value='+products[i].productId+'>'+products[i].name+'</option>');
}
}
return false;
}
/*
function changeProvider(provider,product,blank){
var id = $(provider).val();
if(id == 0) id=null;
var products = dbwtool.callDWRSync('ProductDWR.getProductsByProviderId',[id]);
$(product).empty();
if(blank) $(product).append('<option value=0>全部</option>');
if(products){
for (var i=0;i<products.length;i++){
$(product).append('<option value='+products[i].productId+'>'+products[i].name+'</option>');
}
}
return false;
}*/
function getUnit(productId,unit){
var id = productId;
if(id == 0) id=null;
var dto = dbwtool.callDWRSync('ProductDWR.getProduct',[id]);
if(dto){
$(unit).val(dto.unit);
}
return false;
}
function fomateDateTime(date){
if(date!=null)
return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
else
return "";
}
function fomateDate(date){
if(date!=null)
return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
else
return "";
}
function toDate(s){
if(s==null||s==''){
return null;
}
var date="";
if(date!=null)
date=new Date(Date.parse(s.replace(/-/g,"/")));
return date;
}
/*
*formatFloat(Dight,How):数值格式化函数,
*Dight要 格式化的 数字
*How要保留的小数位数。
*/
function formatFloat(Dight,How)
{
Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How);
return Dight;
}
//显示日历控件
function showDate(id) {
_Ids= document.getElementById(id)
$(_Ids).datepicker({
//showOn: "button",
//buttonImage: "../image/admin/calendar.gif",
//buttonImageOnly: true,
});
}
//获取当前月的第一天
function getFirstDay(myDate){
var year = myDate.getFullYear();
var month = myDate.getMonth()+1;
if (month<10){
month ="0"+month;
}
var firstDay = year+"-"+month+"-"+"01";
return toDate(firstDay);
}
//获取当前月的最后一天
function getLastDay(myDate){
var year = myDate.getFullYear();
var month = myDate.getMonth()+1;
if (month<10){
month ="0"+month;
}
myDate = new Date(year,month,0);
var lastDay =year+"-"+month+"-"+myDate.getDate();
return toDate(lastDay);
}
//根据货币的名称 获取货币的id
function getCurrencyId(name){
var date=fomateDate(new Date());
var dates=toDate(date);
var currencyId = dbwtool.callDWRSync('SyCurrencyDWR.getCurrencyId',[name,dates]);
return currencyId;
}
//判断输入的是整数
function isNumber(Data){
var re = /^[-+]?([0-9]d*|0|[1-9]d{0,2}(,d{3})*)(.d+)?$/;
if(!re.test(Data)){
alert('储位是数字,输入非法!');
return false;
}
else return true;
}
function HashMap(){
var HashMap={
Set:function(key,value){this[key]=value},
Get:function(key,value){return this[key]},
Contains : function(key){return this.Get(key) == null?false:true},
Remove : function(key){delete this[key]}
}
return HashMap;
}
最后
以上就是光亮火为你收集整理的JS经常用的空件函数的全部内容,希望文章能够帮你解决JS经常用的空件函数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复