📄 tools.js
字号:
}else{
return true;
}
}
function dateVerify(objText,blnEmpty,strFormat,strName){
//校验日期的有效性,有效返回true,无效返回false
var strText=objText.value;
if(strText=="" && blnEmpty==false){
alert("‘" + strName + "’不能为空!");
objText.focus();
return false;
}
if(strText!="" && strText.length!=strFormat.length){
alert("‘" + strName + "’的格式不正确,请按照‘" + strFormat + "’格式输入日期!");
objText.focus();
return false;
}
var i,j;
var strFormatTemp;
var strTemp;
for(i=0;i<strText.length;){
strFormatTemp=strFormat.substring(i,i+4);
if(strFormatTemp=="yyyy"){
strTemp=strText.substring(i,i+4);
for(j=0;j<4;j++){
if(strTemp.charCodeAt(j)<48 || strTemp.charCodeAt(j)>57){
alert("‘" + strName + "’的格式不正确,请按照‘" + strFormat + "’格式输入日期!");
objText.focus();
return false;
}
}
i=i+4;
}else{
strFormatTemp=strFormat.substring(i,i+2);
if(strFormatTemp=="MM" || strFormatTemp=="dd" || strFormatTemp=="HH" || strFormatTemp=="mm" || strFormatTemp=="ss"){
strTemp=strText.substring(i,i+2);
for(j=0;j<2;j++){
if(strTemp.charCodeAt(j)<48 || strTemp.charCodeAt(j)>57){
alert("‘" + strName + "’的格式不正确,请按照‘" + strFormat + "’格式输入日期!");
objText.focus();
return false;
}
}
if(strFormatTemp=="MM" && (strTemp>12 || strTemp<1)){
alert("‘" + strName + "’的月份输入不正确,请按照‘" + strFormat + "’格式输入日期!");
objText.focus();
return false;
}
if(strFormatTemp=="dd" && (strTemp>31 || strTemp<1)){
alert("‘" + strName + "’的日期输入不正确,请按照‘" + strFormat + "’格式输入日期!");
objText.focus();
return false;
}
if(strFormatTemp=="HH" && (strTemp>24 || strTemp<0)){
alert("‘" + strName + "’的小时输入不正确,请按照‘" + strFormat + "’格式输入日期!");
objText.focus();
return false;
}
if((strFormatTemp=="mm" || strFormatTemp=="ss") && (strTemp>59 || strTemp<0)){
alert("‘" + strName + "’的时间输入不正确,请按照‘" + strFormat + "’格式输入日期!");
objText.focus();
return false;
}
i=i+2;
}else{
if(strText.substring(i,i+1)!=strFormat.substring(i,i+1)){
alert("‘" + strName + "’的格式不正确,请按照‘" + strFormat + "’格式输入日期!");
objText.focus();
return false;
}
i=i+1;
}
}
}
return true;
}
function doubleVerify(objText,blnEmpty,totalLen,decimalLen,strName) {
//校验带小数数字文本录入的有效性,有效返回true,无效返回false
var strText=objText.value;
var newText=trim(strText);
objText.value=newText;
if(newText=="" && blnEmpty==false) {
alert("‘" + strName + "’不能为空!");
objText.focus();
return false;
}
var i;
for(i=0;i<strText.length;i++) {
if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57) && strText.charCodeAt(i)!=46&& strText.charCodeAt(i)!=69) {
alert("‘" + strName + "’只能填写数字!");
objText.focus();
return false;
}
}
var point=strText.indexOf('.');
if( point==-1) {
if(strText.length > totalLen-decimalLen) {
alert("‘" + strName + "’输入的数字过大,请更正!");
objText.focus();
return false;
}
} else {
if(point > totalLen-decimalLen) {
alert("‘" + strName + "’输入的数字过大,请更正!");
objText.focus();
return false;
}
if(strText.length-(point+1) > decimalLen) {
alert("‘" + strName + "’输入的数字的小数点位数只能有" + decimalLen + "位,请更正!");
objText.focus();
return false;
}
}
return true;
}
// 用于在网页写出 Title
// titleName 要在 Title 栏中显示的内容
function createTitle(titleName){
var strTable = "";
strTable += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
strTable += "<tr align=\"left\">";
strTable += "<td valign=\"top\" background=\"/hollycrm/images/center_bg.gif\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
strTable += "<tr>";
strTable += "<td width=\"1%\"><img src=\"/hollycrm/images/center_1.gif\" width=\"29\" height=\"26\"></td>";
strTable += "<td width=\"99%\" background=\"/hollycrm/images/center_more.gif\" style=\"BACKGROUND-REPEAT:no-repeat;background-position:100% 0%\"><strong><b class=\"a6\" style=\"BACKGROUND-REPEAT: no-repeat\">"+ titleName +"</b></strong></td>";
strTable += "</tr>";
strTable += "</table></td>";
strTable += "</tr>";
strTable += "<tr align=\"left\">";
strTable += "<td valign=\"top\" height=\"10\"></td>";
strTable += "</tr>";
strTable += "</table>";
document.write (strTable);
}
// 检查 Select 是否为空,不为空返回true,空返回false
function selectVerify(objText,strName){
if(objText != null){
if(objText.value != ""){
return true;
}
alert("‘" + strName + "’不能为空!");
objText.focus();
return false;
}else{
alert("‘" + strName + "’不存在!");
return false;
}
}
//textarea限制输入字节个数,idName为textarea的名称,maxlength为最大字节个数。
//例子:<textarea rows="4" cols="30" maxlength=100 id=test onkeypress=doKeypress() onkeydown=doKeydown() ></textarea>
function doKeypress() {
element=document.all["idName"];
maxLength = element.maxlength;
if(!isNaN(maxLength)) {
maxLength = parseInt(maxLength)
var oTR = element.document.selection.createRange()
if(oTR.text.length >= 1) {
event.returnValue = true
} else if (element.value.length > maxLength-1) {
event.returnValue = false;
}
}
}
function doKeydown() {
element=document.all["idName"];
maxLength = element.maxlength;
setTimeout(function(){maxLength = parseInt(maxLength);if(!isNaN(maxLength)){if(element.value.length > maxLength-1){var oTR = window.document.selection.createRange();oTR.moveStart("character", -1*(element.value.length-maxLength));oTR.text = ""}}},1)
}
// 校验checkbox,如果没有选择返回“-1”,如果选择一个选项返回“1”,如果选择多个选项返回“2”
function checkIt(objText) {
var x=0;
for (i=0; i<=(objText.length-1); i++) {
if(objText[i].checked) {
x=x+1;
}
}
if(x==0) {
return -1;
}
if(x==1) {
return 1;
}
if(x>1) {
return 2;
}
}
//==============================================================================
//*******************************************************
//************** Cookie 工具方法 added by HaoBin **********
//*******************************************************
// 设置Cookie
function setCookie(sName, sValue) {
var expires = new Date();
expires.setTime(expires.getTime() + 3 * 30 * 24 * 60 * 60 * 1000);
document.cookie = sName + "=" + escape(sValue) + "; expires=" + expires.toGMTString() + "; path=/";
}
// 取得Cookie
function getCookie(sName) {
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++) {
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0]) {
return unescape(aCrumb[1]);
}
}
// a cookie with the requested name does not exist
return null;
}
// 删除Cookie
function delCookie(sName) {
var expires = new Date();
expires.setTime(expires.getTime() - 1);
document.cookie = sName + "=" + escape(sValue) + "; expires=" + expires.toGMTString();
}
//==============================================================================
//************************************************************************
//************** 全部选中/不选中复选框的工具方法 added by HaoBin **************
//************************************************************************
function checkAllStatus(checkBoxName,value) {
if(hasCheckBoxAvailable(checkBoxName)) {
// Only one checkbox
if(document.all(checkBoxName).length==undefined) {
document.all(checkBoxName).checked=value;
} else {
var checkBoxArray=document.all(checkBoxName);
for(var i=0; i<checkBoxArray.length; i++) {
if(checkBoxArray[i].disabled==false && checkBoxArray[i].checked!=value) {
checkBoxArray[i].checked=value;
}
}
}
}
}
function hasCheckBoxAvailable(checkBoxName) {
var isCheckBoxAvailable=true;
if(document.all(checkBoxName)==null) {
isCheckBoxAvailable=false;
}
return isCheckBoxAvailable;
}
//校验一个值得范围
//obj 需要校验的对象;
//valueType 需要校验的值得类型('number','date')
//alertInfo 提示信息!
function verifyRange(obj,valueType,minValue,maxValue,alertInfo){
var value=obj.value;
if(value.length==0){alert(alertInfo+'不能为空!');obj.focus();return false;}
if(valueType.toUpperCase()=='NUMBER'){
if(parseFloat(value)<parseFloat(minValue)){alert(alertInfo+'的值不能小于最小值:'+minValue);obj.focus();return false;}
if(parseFloat(value)>parseFloat(maxValue)){alert(alertInfo+'的值不能大于最大值:'+maxValue);obj.focus();return false;}
}
else if(valueType.toUpperCase()=='DATE'){
if(value<minValue){alert(alertInfo+'的值不能小于最小值:'+minValue);obj.focus();return false;}
if(value>maxValue){alert(alertInfo+'的值不能大于最大值:'+maxValue);obj.focus();return false;}
}
return true;
}
//==============================================================================
/*
==================================================================
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));
}
-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -