📄 utility.js
字号:
String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g,"");
}
String.prototype.IsInt = function()
{
var re = /^\s*\d+\s*$/;
var chk = false;
if (re.test(this))
{
chk = true;
}
return chk;
}
Array.prototype.Clear = function()
{
while(this.length > 0)
{
this.pop();
}
}
function GetFormValueAsInt(id,defaultValue)
{
var obj = document.getElementById(id);
var result = parseInt(obj.value);
if (result != result)
{
result = defaultValue;
}
return result;
}
function CheckValueInt(id,setFocus)
{
var re = /^\s*\d+\s*$/;
var obj = document.getElementById(id);
var chk = false;
if (re.test(obj.value))
{
chk = true;
}
else
{
if (setFocus)
{
obj.focus();
}
}
return chk;
}
function CheckValueNotEmpty(id,setFocus)
{
var obj = document.getElementById(id);
obj.value = obj.value.trim();
var chk = false;
if (obj.value != "")
{
chk = true;
}
else
{
if (setFocus)
{
obj.focus();
}
}
return chk;
}
function CheckedElementValueIntById(id,message)
{
var chk
chk = CheckValueInt(id,true);
if (!chk)
{
alert(message);
}
return chk;
}
function CheckedElementValueById(id,message)
{
var chk
chk = CheckValueNotEmpty(id,true);
if (!chk)
{
alert(message);
}
return chk;
}
function IsNullOrEmptyValue(id,message)
{
var chk = true;
var obj = document.getElementById(id);
if (obj != null)
{
if ((obj.value != "") && (obj.value != null))
{
chk = false;
}
else
{
obj.focus();
}
}
if (chk)
{
alert(message);
}
return chk;
}
function DisplayBlock(id,value)
{
var obj = document.getElementById(id);
if (obj != null)
{
obj.style.display = value;
}
else
{
alert("找不到对象" + id);
}
}
function ChangeDisplay(id)
{
var obj = document.getElementById(id);
if (obj != null)
{
if (obj.style.display == "none")
{
obj.style.display = "block";
}
else
{
obj.style.display = "none";
}
}
}
function SetStyleClass(id,className)
{
var obj = document.getElementById(id);
obj.setAttribute("class",className);
obj.setAttribute("className",className);
}
function getQueryString(name)
{
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
// var r = document.URL.substr(1).match(reg);
var r = window.location.search.substr(1).match(reg);
var result = null;
if (r != null)
{
result = unescape(r[2]);
}
return result;
}
function SetSelectedByValue(value,id)
{
var obj = document.getElementById(id);
if (obj != null)
{
for (var i = 0; i < obj.options.length; i++)
{
if (obj.options[i].value == value)
{
obj.options[i].selected = true;
break;
}
}
}
}
function GB2UTF8(data)
{
var glbEncode = [];
gb2utf8_data = data;
execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
t=t.split("@");
var i=0,j=t.length,k;
while(++i<j)
{
k=t[i].substring(0,4);
if(!glbEncode[k])
{
gb2utf8_char = eval("0x"+k);
execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
glbEncode[k]=escape(gb2utf8_char).substring(1,6);
}
t[i]=glbEncode[k]+t[i].substring(4);
}
gb2utf8_data = gb2utf8_char = null;
return unescape(t.join("%"));
}
function CreateElement(tagname,id,value,className,style,type)
{
var ele = document.createElement(tagname);
if (id != null)
{
ele.setAttribute("id",id);
}
if (value != null)
{
ele.setAttribute("value",value);
}
if (className != null)
{
ele.setAttribute("class",className);
ele.setAttribute("className",className);
}
if (style != null)
{
ele.setAttribute("style",style);
ele.style.cssText = style;
}
if (type != null)
{
ele.setAttribute("type",type);
}
return ele;
}
function RelpaceRN(value)
{
return value.replace(/\|r\|n\|/gi,"\r\n").replace(/\|r\|/gi,"\r").replace(/\|n\|/gi,"\n");
}
function ClearObjectChildren(id)
{
var obj = document.getElementById(id);
if(obj != null)
{
while(obj.childNodes.length > 0)
{
obj.removeChild(obj.childNodes[0]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -