//发一些自己经常使用的js
//不要拿西瓜砸我
//写的不好请留言给我
//功能:获取指定id的DOM对象
function $(ctrlID)
{
return document.getElementById(ctrlID);
}
//获取当天日期
function currDate(ctrlId)
{
var currDate=new Date();
var m=parseInt(currDate.getMonth())+1;
var d=parseInt(currDate.getDate());
if(m<10)
{
m="0"+m;
}
if(d<10)
{
d="0"+d;
}
ctrlId.value = currDate.getYear()+"-"+m+"-"+d;
}
//获取当月日期(尽有年月)
function currDate_YM(ctrlId)
{
var currDate=new Date();
var m=parseInt(currDate.getMonth())+1;
if(m<10)
{
m="0"+m;
}
ctrlId.value = currDate.getYear()+"-"+m;
}
//获取下个月日期(尽有年月)
function currDate_YM_Next(ctrlId)
{
var currDate=new Date();
var y=parseInt(currDate.getYear());
var m=parseInt(currDate.getMonth())+1;
if(m==12)
{
y=y+1;
m=1;
}
else m+=1;
if(m<10)
{
m="0"+m;
}
ctrlId.value = y+"-"+m;
}
//显示divID标签内容
function showDiv(divID)
{
$(divID).style.visibility="visible";
}
//隐藏divID标签内容
function hideDiv(divID)
{
$(divID).style.visibility="hidden";
}
//设置divid标签位置
function setIdPosition(divid)
{
var x=document.body.scrollLeft+event.clientX;
var y=document.body.scrollTop+event.clientY;
var a=window.event.offsetX;
var b=window.event.offsetY;
x=x-a-3;
y=y-b;
y=y+17;
$(divid).style.left = x;
$(divid).style.top = y;
}
//点击即拷贝obj对象内容
var selectcopy = function(obj)
{
return function()
{
select_copy(obj);//该函数为外部定义的一个执行函数;
}
}
function select_copy(obj_str){
var sel=document.body.createTextRange();
sel.moveToElementText(obj_str);
sel.select();
document.execCommand("copy");
}
//获得一个数的中文大写
function NumToUpperCase(num)
{
if(num == "0") return "";
var list1 = new Array("","壹","贰","叁","肆","伍","陆","柒","捌","玖");
var list2 = new Array("拾","百","仟","萬","亿");
var money = num.split(".");
if(money[0].length>12)
{
alert("您要计算的内容大于可计算的范围!");
return;
}
var moneysum = "圆";
for(var i = 0; i<money[0].length; i++)
{
switch ((i + 1) % 4)
{
case 1:
{
if((i + 1)/4 < 1) {moneysum = list1[money[0].substring(money[0].length - i - 1,money[0].length - i)] + moneysum; break;}
var ling = "";
if(money[0].substring(money[0].length - i,money[0].length - i + 1) == 0) ling = SingleNumToUpperCase(0);
if((i + 1)/4 < 2) {moneysum = list1[money[0].substring(money[0].length - i - 1,money[0].length - i)] + list2[3] + ling + moneysum; break;}
if((i + 1)/4 < 3) {moneysum = list1[money[0].substring(money[0].length - i - 1,money[0].length - i)] + list2[4] + ling + moneysum; break;}
}
case 2:
{
if(money[0].substring(money[0].length - i - 1,money[0].length - i) != 0)
{moneysum = list1[money[0].substring(money[0].length - i - 1,money[0].length - i)] + list2[0] + moneysum; }
break;
}
case 3:
{
if(money[0].substring(money[0].length - i - 1,money[0].length - i) != 0)
{moneysum = list1[money[0].substring(money[0].length - i - 1,money[0].length - i)] + list2[1] + moneysum; }
break;
}
case 0:
{
if(money[0].substring(money[0].length - i - 1,money[0].length - i) != 0)
{moneysum = list1[money[0].substring(money[0].length - i - 1,money[0].length - i)] + list2[2] + moneysum; }
break;
}
default: break;
}
}
if(money.length == 2)
{
if(parseFloat(money[1].substring(0,2)) == 0) {moneysum += "整"; }
else
{
moneysum += SingleNumToUpperCase(money[1].substring(0,1)) + "角";
if(money[1].length > 1)
if(parseInt(money[1].substring(1,2)) != 0)
moneysum += list1[money[1].substring(1,2)] + "分";
}
}
else moneysum += "整";
return moneysum;
}
//获得个位数的中文大写
function SingleNumToUpperCase(num)
{
var list1 = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
return list1[num];
}
//设置小数点位数
function setNumPoint(num, pointnum)
{
if(num == "0") return 0;
var numsplit = num.split(".");
var numsum = numsplit[0];
if(pointnum > 0) numsum += ".";
else return numsum;
for(var i = 0; i<pointnum; i++)
{
if(numsplit.length > 1)
if(numsplit[1].length >= i + 1)
{
numsum += numsplit[1].substring(i, i + 1);
}
else
{
numsum += "0";
}
else numsum += "0";
}
return numsum;
}
//格式化大量id对象值合并为自己想要的代码
function FormatObject()
{
}
//设置id数组
FormatObject.prototype.setArrayObj = function(arryobj)
{
var arrayobj;
this.arrayobj = arryobj;
}
//得到所有对象值(通过分隔符分开)
FormatObject.prototype.getArrayIdContext = function()
{
var str = $(this.arrayobj[0]).value;
for(var i = 1; i < this.arrayobj.length; i++)
{
str += cellspl + $(this.arrayobj[i]).value;
}
return str;
}
//设置对象属性
FormatObject.prototype.setArrayObjAttribute = function(readOnlyArray)
{
for(var i = 0; i < this.arrayobj.length; i++)
{
var idObj = $(this.arrayobj[i]);
idObj.readOnly = (readOnlyArray == "true" ? "true" : "false");
}
}
//格式化input<text>
function FormatInputText()
{
var onlyNumText = "", numPointText = "", onlyChinaText = "", commonText = "";
this.onlyNumText = "";
this.numPointText = "";
this.onlyChinaText = "";
this.commonText = "";
}
//获得竟能输入数字的input
FormatInputText.prototype.getOnlyNum = function(objid, stylecont, classcont, readonly)
{
if(stylecont != "" && stylecont != null)
stylecont = " style=/"" + stylecont + "/" ";
else
stylecont = "";
if(classcont != "" && classcont != null)
classcont = " class=/"" + classcont + "/" ";
else
classcont = "";
if(readonly == "true")
readonly = " readonly=/"readonly/" ";
else
readonly = "";
return "<input id=/"" + objid + "/" οnkeyup=/"this.value=this.value.replace(D//g,/'/')/" onafterpaste=/"this.value=this.value.replace(D//g,/'/')/" " + stylecont + classcont + readonly + ">";
}
//获得输入带小数点的数字input
FormatInputText.prototype.getNumPoint = function(objid, stylecont, classcont, readonly, checkproduct)
{
if(stylecont != "" && stylecont != null)
stylecont = " style=/"" + stylecont + "/" ";
else
stylecont = "";
if(classcont != "" && classcont != null)
classcont = " class=/"" + classcont + "/" ";
else
classcont = "";
if(readonly == "true")
readonly = " readonly=/"readonly/" ";
else
readonly = "";
if(checkproduct != "")
checkproduct = "TableProperty_checkride(" + checkproduct + ");";
return "<input id=/"" + objid + "/" t_value=/"/" o_value=/"/" οnkeypress=/"if(!this.value.match(//^[//+//-]?//d*?//.?//d*?$//))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(//^(?:[//+//-]?//d+(?://.//d+)?)?$//))this.o_value=this.value/" οnkeyup=/"if(!this.value.match(//^[//+//-]?//d*?//.?//d*?$//))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(//^(?:[//+//-]?//d+(?://.//d+)?)?$//))this.o_value=this.value;" + checkproduct + "/" οnblur=/"if(!this.value.match(//^(?:[//+//-]?//d+(?://.//d+)?|//.//d*?)?$//))this.value=this.o_value;else{if(this.value.match(//^//.//d+$//))this.value=0+this.value;if(this.value.match(//^//.$//))this.value=0;this.o_value=this.value}/" " + stylecont + classcont + readonly + ">";
}
//获得尽能输入中文的input
FormatInputText.prototype.getOnlyChina = function(objid, stylecont, classcont, readonly)
{
if(stylecont != "" && stylecont != null)
stylecont = " style=/"" + stylecont + "/" ";
else
stylecont = "";
if(classcont != "" && classcont != null)
classcont = " class=/"" + classcont + "/" ";
else
classcont = "";
if(readonly == "true")
readonly = " readonly=/"readonly/" ";
else
readonly = "";
return "<input id=/"" + objid + "/" οnkeyup=/"value=value.replace(//[ -~]//g,/'/')/" οnkeydοwn=/"if(event.keyCode==13) event.keyCode=9/" " + stylecont + classcont + readonly + ">";
}
//获得普通input
FormatInputText.prototype.getCommonText = function(objid, stylecont, classcont, readonly)
{
if(stylecont != "" && stylecont != null)
stylecont = " style=/"" + stylecont + "/" ";
else
stylecont = "";
if(classcont != "" && classcont != null)
classcont = " class=/"" + classcont + "/" ";
else
classcont = "";
if(readonly == "true")
readonly = " readonly=/"readonly/" ";
else
readonly = "";
return "<input id=/"" + objid + "/" type=/"text/" " + stylecont + classcont + readonly + " //>"
}
/*LTrim(string):去除左边的空格*/
function LTrim(str){
var whitespace=new String(" /t/n/r");
var s=new String(str);
if(whitespace.indexOf(s.charAt(0))!=-1){
var j=0,i=s.length;
while(j<i&&whitespace.indexOf(s.charAt(j))!=-1){
j++;
}
s=s.substring(j,i);
}
return s;
}
/*RTrim(string):去除右边的空格*/
function RTrim(str){
var whitespace=new String(" /t/n/r");
var s=new String(str);
if(whitespace.indexOf(s.charAt(s.length-1))!=-1){
var i=s.length-1;
while(i>=0&&whitespace.indexOf(s.charAt(i))!=-1){
i--;
}
s=s.substring(0,i+1);
}
return s;
}
/*Trim(string):去除字符串两边的空格*/
function Trim(str){
return RTrim(LTrim(str));
}
//拖拽div定义
function DivDrag() {
var obj, ox, oy;
function startDrag(e) {
//当按下时初始化参数
var e = window.event || e;
obj = this.root;
ox = e.clientX - obj.offsetLeft;
oy = e.clientY - obj.offsetTop;
document.onmousemove = moveDrag;
document.onmouseup = stopDrag;
}
function moveDrag(e) {
//鼠标移动时改变obj的位置
var e = window.event || e;
obj.style.left = e.clientX - ox + "px";
obj.style.top = e.clientY - oy + "px";
}
function stopDrag() {
//当松开时清除onmousemove方法
document.onmousemove = document.onmouseup = null;
}
this.add = function (o, root) {
//添加对象
o.root = root;
o.onmousedown = startDrag;
};
}