📄 function.js
字号:
/*
* ??num??10??num???????? 2 ??? 02
*/
function changeNumberDisplay(num){
var rtn = "";
if(num < 10){
rtn = "0" + num;
}else{
rtn = num;
}
return rtn;
}
/*
?????trim
????: ?????????????
??????????
???????????
*/
function trim(str){
return str.replace(/(^\s*)|(\s*$)/g, "");
}
/*
?????isPoint
????: ??????????????
??????????
?????true or false
*/
function isIncludePoint(string){
if(string.indexOf(".")!=-1){
return true;
}
else{
return false;
}
}
function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" "); //??????????
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}
function isChn(d) {
actlen=d.length;
for(i=0;i<d.length;i++)
if (d.substr(i,1)>"~")
actlen+=1;
if( actlen>d.length )
return true;
return false;
}
function isBirthDate(d) {
var first,second,yy,mm,dd;
var today = new Date();
if(d.indexOf("/")!=-1)
{
first=d.indexOf("/");
second=d.lastIndexOf("/");
if(second==first) return false;
yy=parseInt(d.substring(0,first));
if ( d.substr(first + 1, 1) == '0' )
mm=parseInt(d.substring(first+2,second));
else
mm=parseInt(d.substring(first+1,second));
if ( d.substr(second + 1, 1) == '0' )
dd=parseInt(d.substring(second+2,d.length));
else
dd=parseInt(d.substring(second+1,d.length));
if (isNaN(yy)) { //Error Year Format
return false;
}
if (yy<30)
yy += 2000;
else if (yy <100 && yy >= 30)
yy += 1900;
if( yy < 1900 || yy>2069) return false;
if (isNaN(mm) || mm < 1 || mm > 12) { //Error Month Format
return false;
}
if (isNaN(dd) || dd < 1 || dd > 31) { //Error Month Format
return false;
}
d = new Date(yy, mm - 1, dd); //Test the Date
if (isNaN(d)) { //Error Date Format
return false;
}
if (d.getMonth() != mm - 1 || d.getDate() != dd) { //invalid date such as '1999/02/29' and '1999/04/31'
return false;
}
if ( yy + 16 > today.getFullYear() ) return false;
return d.toLocaleString(); //Return the Date in parsed format
}
else if(d.indexOf("-")!=-1)
{
first=d.indexOf("-");
second=d.lastIndexOf("-");
if(second==first) return false;
yy=parseInt(d.substring(0,first));
if ( d.substr(first + 1, 1) == '0' )
mm=parseInt(d.substring(first+2,second));
else
mm=parseInt(d.substring(first+1,second));
if ( d.substr(second + 1, 1) == '0' )
dd=parseInt(d.substring(second+2,d.length));
else
dd=parseInt(d.substring(second+1,d.length));
if (isNaN(yy)) { //Error Year Format
return false;
}
if (yy<30)
yy += 2000;
else if (yy <100 && yy >= 30)
yy += 1900;
if( yy < 1950 || yy>2069) return false;
if (isNaN(mm) || mm < 1 || mm > 12) { //Error Month Format
return false;
}
if (isNaN(dd) || dd < 1 || dd > 31) { //Error Month Format
return false;
}
d = new Date(yy, mm - 1, dd); //Test the Date
if (isNaN(d)) { //Error Date Format
return false;
}
if (d.getMonth() != mm - 1 || d.getDate() != dd) { //invalid date such as '1999/02/29' and '1999/04/31'
return false;
}
if ( yy + 16 > today.getFullYear() ) return false;
return d.toLocaleString(); //Return the Date in parsed format
}
else
return false;
}
function isInt(n) {
var i = parseInt(n*1);
if (i == NaN) {
return false;
}
if (i != n){
return false;
}
return true;
}
function isMail(str) {
if (trim(str) == ""){
return true;
}
var a=str.indexOf("@")+1;
var p=str.indexOf(".")+1;
if(str.indexOf("'") > 0)
return false;
if(str.indexOf('"') > 0)
return false;
if (a<2)
return false;
if (p<1)
return false;
if (p<a+2)
return false;
if (str.length==p)
return false;
return true;
}
function isFloat(str) {
var ch=str.charAt(0);
if( ch == "." ) return false;
for (var i=0; i < str.length; i++)
{ ch=str.charAt(i);
if ((ch != ".") && (ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") && (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9"))
return false;
}
return true;
}
function isNumber(str) {
for (var i=0; i < str.length; i++)
{ var ch=str.charAt(i);
if ((ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") && (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9"))
return false;
}
return true;
}
function CheckUserInput(vstrInput) {
var intIndex;
var intCharCount;
for(intIndex = 0; intIndex < vstrInput.length; intIndex++){
if (vstrInput.charCodeAt(intIndex) < 48)
return false;
if ((vstrInput.charCodeAt(intIndex) > 57) && (vstrInput.charCodeAt(intIndex) < 64))
return false;
if ((vstrInput.charCodeAt(intIndex) > 90) && (vstrInput.charCodeAt(intIndex) < 97))
return false;
if (vstrInput.charCodeAt(intIndex) > 122)
return false;
}
return true;
}
function isPhone(str){
var intIndex;
var intCharCount;
for(intIndex = 0; intIndex < str.length; intIndex++){
if(str.charCodeAt(intIndex) < 32)
return false;
if(str.charCodeAt(intIndex) == 34)
return false;
if(str.charCodeAt(intIndex) == 39)
return false;
if(str.charCodeAt(intIndex) > 126)
return false;
}
return true;
}
/*
?????checkString()
????: ????&?????<?>?:?;?????;
?????32?????48~57?????65~90???????95??????97~122???????>127?????
??????????
???????????
*/
function checkString(str){
var strChar = str;
var isValid = true;
for (var i = 0; i < str.length; i++){
if ( (str.charCodeAt(i) == 32) || ((str.charCodeAt(i) >= 48) && (str.charCodeAt(i) <= 57)) || ((str.charCodeAt(i) >= 65) && (str.charCodeAt(i) <= 90)) || (str.charCodeAt(i) == 95) || ((str.charCodeAt(i) >= 97) && (str.charCodeAt(i) <= 122)) || (str.charCodeAt(i) > 127) ) {
// do nothing
} else {
isValid = false;
break;
}
}
return isValid;
}
/*
?????selectToString(selectObject)
????: ?select??????????????
?????select??
????????
?????2001/08/30
*/
function selectToString(selectObject){
var str = "";
for(var i = 0; i < selectObject.length; i++){
str = str + selectObject(i).value + ",";
}
if(str.substr(str.length - 1, 1) == ",")
str = str.substr(0, str.length - 1);
return str;
}
/*
?????CheckPostCode(str)
????: ????????
?????str??????
?????true or false
*/
function CheckPostCode(str){
if (trim(str) == ""){
return true;
}
for (var i=0; i < str.length; i++){
var ch=str.charAt(i);
if ((ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") && (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9"))
return false;
else
return true;
}
}
/**
*?????selectByValue
*?????srcName--Select?????
* value----?????
*??? ??
*?? ?selectByValue("s", "2")
*/
function selectByValue(srcName, value) {
var o = document.all(srcName);
if( o==null || o.tagName!="SELECT" ) return;
var length = o.options.length;
for( var i=0; i<length; i++ ) {
var oOption = o.options[i];
if( value==oOption.value) {
o.selectedIndex = i;
return;
}
}
}
function selectByText(srcName, text) {
var o = document.all(srcName);
if( o==null || o.tagName!="SELECT" ) return;
var length = o.options.length;
for( var i=0; i<length; i++ ) {
var oOption = o.options[i];
if( text==oOption.value) {
o.selectedIndex = i;
return;
}
}
}
function maxwin(){
var larg=screen.availWidth;
var altez=screen.availHeight;
self.resizeTo(larg,altez);
self.moveTo(0,0);
}
function handleEnter (field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
var i;
for (i = 0; i < field.form.elements.length; i++)
if (field == field.form.elements[i])
break;
i = (i + 1) % field.form.elements.length;
field.form.elements[i].focus();
return false;
}
else
return true;
}
function passwordcheck(val){
if(val=="88888888"){
return true ;
}
else
{
return false ;
}
}
//????????
function rollIn(el){
var ms = navigator.appVersion.indexOf("MSIE");
ie4 = (ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+6)) >= 4)
if(ie4)
{
//el.initstyle=el.style.cssText;
el.style.cssText=el.fprolloverstyle;
}
}
function rollOut(el){
var ms = navigator.appVersion.indexOf("MSIE");
ie4 = (ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+6)) >= 4)
if(ie4){
el.style.cssText=el.fprolloverstyle2;
}
}
//??????????
function change_src(imagename){
switch(imagename){
case "??" : document.write("<img title='??' src='../image/tj.gif' height=15 width=16>");break;
case "??" : document.write("<img title='??' src='../image/jj.gif' height=14 width=16>");break;
default: document.write(" ");break;
}
}
//??????????
function screen_check(){
var correctwidth=1024;
var correctheight=768;
if (screen.width!=correctwidth||screen.height!=correctheight){
alert("????????: "+correctwidth+"*"+correctheight+". ????????:"+screen.width+"*"+screen.height+"?????????????????????")
return ;
}
}
function screen_check1(){
if((screen.width == 1024 && screen.height == 768) || (screen.width == 800 && screen.height == 600)){
}else{
alert("??????????: 1024*768?800*600. ????????:"+screen.width+"*"+screen.height+"?????????????????????")
return ;
}
}
function addElement(document,kind,val){
var ele = document.createElement(kind);
if(val == ""){
ele.appendChild(document.createTextNode(" "));
}else{
ele.appendChild(document.createTextNode(val));
}
ele.align = "left";
return ele;
}
function updateElementText(id,val){
var pageTitle = document.getElementById(id);
var child = pageTitle.childNodes;
pageTitle.removeChild(child[0]);
var pageTitleText = document.createTextNode(val);
pageTitle.appendChild(pageTitleText);
}
function createElementByInnerHTML(kind,innerHTMLValue){
var ele = document.createElement(kind);
ele.align = "left";
ele.innerHTML = innerHTMLValue;
return ele;
}
function appendElement(targetEle,kind,innerHTMLValue,width,align){
var ele = createElementByInnerHTML(kind,innerHTMLValue);
if(kind == "td" && width){
ele.width = width;
}
if (align){
ele.align=align;
}
targetEle.appendChild(ele);
}
function createXMLHttpRequest(){
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -