常用腳本函數(shù)
/*
==================================================================
打開網(wǎng)頁對話框
==================================================================
*/
function Dialog(targeturl,width,height,scroll)
{
var sFeature = "dialogWidth:" + width + ";dialogHeight:" + height + ";scroll=1" ;
window.showModelessDialog(targeturl,"dialog",sFeature)
}
/*
==================================================================
打開窗體
==================================================================
*/
function winOpen(targeturl,width,height,scroll)
{
var left=(window.screen.width-width)/2 ;
var top=(window.screen.height-height)/2 ;
var arrt ="status=no, menubar=no,scrollbars=" + scroll + ",resizable=no,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left ;
window.open(targeturl,"win_pdown",arrt) ;
}
/*
==================================================================
得到checkbox選中的值
==================================================================
*/
function GetSelectedValue(chkName) {
var frm=document.forms[0];
var selectedValue = "" ;
var blnChecked=false;
for(var i=0;i<frm.elements.length;i++){
var e=frm.elements[i];
if((e.name== chkName)&&e.checked){
blnChecked=true;
if (selectedValue == "" )
selectedValue = e.value ;
else
selectedValue = selectedValue + "," + e.value ;
}
}
if(!blnChecked)
alert("請至少選擇一條記錄!");
return selectedValue ;
}
/*
==================================================================
設置全選
==================================================================
*/
function CheckAll(chk_Obj,chkName)
{
var form = document.forms[0] ;
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
if (e.name == chkName)
e.checked = chk_Obj.checked;
}
}
/*
==================================================================
兩個ListBox項移動
==================================================================
*/
function MoveLst(oSelSource,oSelDest)
{
var nLength = oSelDest.length;
var sText,sVal ;
var i, j;
var bTag = 0 ;
for(i=0; i<oSelSource.length;i++)
{
if (oSelSource.options[i].selected)
{
sText = oSelSource.options[i].text ;
sVal = oSelSource.options[i].value ;
for(j=0; j<nLength; j++)
{
if((sText==oSelDest.options[j].text) && (sVal==oSelDest.options[j].value)) //判斷此項如果已經(jīng)存在,不用添加
{
bTag = 1 ;
break;
}
}
if(bTag == 0)
{
oSelDest.options[nLength] = new Option(sText,nLength);
oSelDest.options[nLength].value = sVal;
nLength++;
}
oSelSource.options[i] = null ;
}
}
}
/*
==================================================================
得到LISTBOX的值 1,2
==================================================================
*/
function getLstValue(objLst)
{
var oLst = objLst ;
var strValue = "" ;
for(i=0;i<oLst.length ;i++)
{
strValue = strValue + oLst.options[i].value + "," ;
}
if (strValue.length > 0 )
{
strValue = strValue.substring(0,strValue.length-1)
}
return strValue
}
function validEmail(oEmail) {
var emailV = oEmail.value ;
if (emailV.length < 6) return false;
if (emailV.indexOf("@") < 1) return false;
if (emailV.indexOf("@") > (emailV.length-4)) return false;
for (var i=0; i < emailV.length; i++) {
var tempV = emailV.substring(i, i+1)
if (tempV == " " || tempV == "'" || tempV == '"' || tempV == "," || tempV == ";" || tempV == "`" || tempV == "<" || tempV == ">") {
oEmail.focus();
return false;
}
}
return true;
}
function validSelect(oSelect)
{
if (oSelect.options[oSelect.selectedIndex].value == "")
{
return false ;
oSelect.focus();
}
return true
}
function validRadio(oRadio)
{
for( var i=0;i<oRadio.length;i++)
{
if (oRadio[i].checked == true)
{
return true ;
}
}
oRadio.focus();
return false
}
function isInteger(inputVal){
inputStr = inputVal.toString();
for (var i=0; i< inputStr.length; i++){
var oneChar = inputStr.charAt(i)
if (oneChar < "0" || oneChar > "9"){
return false;
}
}
return true;
}
function isNumeric(vNumber)
{
inputStr = vNumber;
for (var i=0; i< inputStr.length; i++){
var oneChar = inputStr.charAt(i)
if (oneChar != ".")
{
if (oneChar < "0" || oneChar > "9"){
return false;
}
}
}
return true;
}
function isEmpty(oInput)
{
oInput.value = trim(oInput.value) ;
if (oInput.value == "")
{
//oInput.focus() ;
return true ;
}
else
{
return false;
}
}
function trim(vInString)
{
var strTemp=""+vInString+"";
while(strTemp.charAt(0)==" ")
{
strTemp=strTemp.substring(1);
}
while(strTemp.charAt(strTemp.length-1)==" ")
{
strTemp=strTemp.substring(0,strTemp.length-1);
}
return strTemp;
}
function checkDateInput(vString)
{
if(!/^[1|2]\d{3}-\d{1,2}-\d{1,2}$/.test(vString))
{
alert("格式錯誤!可能是以下原因造成的:\n\n - 輸入框為空;\n - 格式錯誤,正確的格式類似“2003-3-15”;\n - 年份不符合實際。");
return false;
}
return true;
}
function ConfirmDelete()
{
if (confirm("您真的要刪除選擇的記錄嗎!"))
{
return true ;
}
else
{
return false ;
}
}
function isSelected(oSel)
{
if (oSel.length == 0) return false ;
if (oSel.options[oSel.selectedIndex].value == "") 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));
}