⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customform.js

📁 医院信息系统(Hospital Information System
💻 JS
字号:
function  jtrim(s)
{
    var  i,b=0,e=s.length;
    for(i=0;i<s.length;i++)
        if(s.charAt(i)!=' '){b=i;break;}
    if(i==s.length)
        return  "";
    for(i=s.length-1;i>b;i--)
        if(s.charAt(i)!=' '){e=i;break;}
    return  s.substring(b,e+1);
}

function init(){
	var showType=document.getElementById("pageShowType").value;
	var curMenuID=document.getElementById("menuID").value;
	var userID=parent.document.getElementById("userID").value;
	showType=encodeURI(showType).replace(/\%/g,"!");
	parent.document.frames["upButton"].location.href="buttonShowAction.do?showType="+showType+"&pagename=upbutton"+"&menuID="+curMenuID+"&userID="+userID;
	parent.document.frames["downButton"].location.href="buttonShowAction.do?showType="+showType+"&pagename=downbutton"+"&menuID="+curMenuID+"&userID="+userID;
	
	if(document.getElementById("saveStatus").value=="4"){
		document.getElementById("returnPage").style.display="inline";
		parent.document.frames["upButton"].location.href="/pages/blank.html";
		parent.document.frames["downButton"].location.href="/pages/blank.html";
	}
	
	var myTable=document.getElementById("table1");
	for(var i=0;i<myTable.rows.length;i++){
		myTable.rows[i].cells[0].width="150px";
		myTable.rows[i].cells[0].align="right";
	}

	var allStar=document.getElementsByName("star");
	for(var i=0;i<allStar.length;i++){
		allStar[i].src="/images/star.gif";
	}
	var allCoding=document.getElementsByName("coding");
	for(var i=0;i<allCoding.length;i++){
		allCoding[i].src="/images/coding.gif";
		allCoding[i].attachEvent("onmouseover", changeCodingImage);
		allCoding[i].attachEvent("onmouseout", changeCodingImageBack);
	}

	for(var i=0;i<myTable.rows.length;i++){
		var curInput=myTable.rows[i].cells[1].firstChild;
		if(curInput.inputEnable=="0"){
			curInput.readOnly=true;
		}
		if(curInput.rows!=null&&curInput.rows!=""){
			curInput.style.height=curInput.rows*20;
		}
	}
	
	var myStatus = document.getElementById("saveStatus").value;
	switch(myStatus){
		case "0":
			break;
		case "1":
			alert("保存成功!");
			changeKeyInputDisable();
			break;
		case "-1":
			alert("很抱歉,保存失败!");
			break;
		case "2":
			alert("很抱歉,关键字重复,无法保存!");
			break;
		case "3":
			alert("修改成功!");
			changeKeyInputDisable();
			break;
		case "-3":
			alert("很抱歉,修改失败!");
			changeKeyInputDisable();
			break;
		default:
			//alert(myStatus);
			break;
	}
}

function changeKeyInputDisable(){
	/*var myTable=document.getElementById("table1");
		for(var i=0;i<myTable.rows.length;i++){
		var curInput=myTable.rows[i].cells[1].firstChild;
		if(curInput.inputEnable=="0"){
			curInput.readOnly=true;
		}
	}*/
	
	/*var allInput=document.getElementsByTagName("INPUT");
	for(var i=0;i<allInput.length;i++){
		if(allInput[i].className=="singleRow"){
			if(allInput[i].isKey=="1"){
				//alert();
				//allInput[i].disabled=true;
			}
		}
	}*/
}

function changeCodingImage(){
	event.srcElement.src="/images/codingmouseover.gif";
}

function changeCodingImageBack(){
	event.srcElement.src="/images/coding.gif";
}

//保存前处理
function checkBeforeSave(){
	var myTable=document.getElementById("table1");
	for(var i=0;i<myTable.rows.length;i++){
		var curInput=myTable.rows[i].cells[1].firstChild;
		if(checkData(curInput)==false){
			document.getElementById("saveForm").value="0";
			return false;
		}
	}
	document.getElementById("saveForm").value="1";
	
	var keyNamesInput=document.getElementById(document.getElementById("keyNames").value);
	document.getElementById("keyValues").value=keyNamesInput.value;
	
	return true;
}

//检查数据的合法性,保存的时候对每个输入框执行checkData,
//而离开焦点事件发生的时候,对每个输入框执行仅执行checkDataKind
function checkData(curInput){
	return checkNullFlag(curInput)&&checkDataKind(curInput);
}

//检查数据项能否为空的约束
function checkNullFlag(curInput){
	if(curInput.notNullFlag==1){
		//必填项不能为空,除非该文本栏是auto类型的。
		if(jtrim(curInput.value)==""&&curInput.fieldType!="auto"){
			alert("“"+curInput.name+"”"+"一栏不能为空!");
			return false;
		}
	}
	return true;
}

//检查所填的数据类型是否符合要求,比如int型和date型
function checkDataKind(curInput){
	var result=true;
	if(curInput.fieldType=="int"){
		result=checkDataInt(curInput);
	}

	if(curInput.fieldType=="date"){
		result=checkDataDate(curInput);
	}
	
	if(curInput.fieldType=="repassword"){
		result=checkDataPassword(curInput);
	}
	
	if(curInput.fieldType=="sellprice"){
		result=checkDataPrice(curInput);
	}
	
	return result;
}

function checkDataInt(curInput){
	if(jtrim(curInput.value)!=""&&isNaN(curInput.value)==true){
		alert("“"+curInput.name+"”"+"一栏必须填数字!");
		return false;
	}
}

function checkDataDate(curInput){
	if(jtrim(curInput.value)!=""&&isDate(curInput.value)==false){
		alert("“"+curInput.name+"”"+"一栏的格式为:yyyy-mm-dd");
		return false;
	}
}

function checkDataPassword(curInput){
	var myTable=document.getElementById("table1");
	for(var i=0;i<myTable.rows.length;i++){
		var curInput2=myTable.rows[i].cells[1].firstChild;
		if(curInput2.fieldType=="password"){
			if(curInput.value!=curInput2.value){
				alert("对不起,“"+curInput2.name+"”字段和“"+curInput.name+"”字段的内容必须完全一致,请重新输入!");
				curInput.value="";
				return false;
			}
		}
	}
}


function checkDataPrice(curInput){
	var myTable=document.getElementById("table1");
	for(var i=0;i<myTable.rows.length;i++){
		var curInput2=myTable.rows[i].cells[1].firstChild;
		if(curInput2.fieldType=="buyprice"){
			if(parseFloat(curInput.value)<parseFloat(curInput2.value)){
				alert("对不起,“"+curInput.name+"”字段的数值必须大于“"+curInput2.name+"”字段的数值,请重新输入!");
				return false;
			}
		}
	}
}

//控制显示编码按钮所打开的页面
function showCode(codeType, curCoding,codeCascade){
	var targetInput=curCoding.parentNode.firstChild;
	var codeValue;
	if(codeType=="date"||codeType=="smalldate"){
		codeValue=window.showModalDialog("/pages/date.html","","dialogWidth=200px;dialogHeight=200px;scroll=auto;status=no;resizable=no");
	}
	else{
		//准备联动机制
		if(codeCascade!=""){
			var myTable=document.getElementById("table1");
			for(var i=0;i<myTable.rows.length;i++){
				var curInput=myTable.rows[i].cells[1].firstChild;
				if(curInput.codeType==codeCascade){
					//alert(curInput.value);
				}
			}
		}
		codeValue=window.showModalDialog("/codingAction.do?codetype="+codeType,"","dialogWidth=200px;dialogHeight=200px;scroll=auto;status=no;resizable=no");
	}

	if(codeValue!=null){
		targetInput.value=codeValue;
	}
}

//检查输入的日期格式是否符合yyyy-mm-dd的形式
function isDate(str){ 
	var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/
	if (reg.test(str)){
		return true;
	}
	return false;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -