JSTL下拉框默选象及一些公用的JS

 

<td>
  <select name="cmsMember.isPass" style="font-size=9pt" id="isPass">
 <option value="">--请选择--</option>
 <option value="0">待验证</option>
 <option value="1">已验证</option>
  </select>
 <script>checkDropListItem(document.getElementById("isPass"),'${cmsMember.isPass}');</script>
</td>


// JavaScript Document

function checkDropListItem(obj,itemvalue)
{
 /*
 默认选中下拉列表框中的具有某个值的一项
 obj:下拉列表框对象
 itemvalue:该项值
 */
 for(i=0;i<obj.options.length;i++)
 {
  if(obj.options[i].value==itemvalue)
     obj.selectedIndex=i;
 }
}

function checkRadioListItem(obj,itemvalue)
{
 /*
 默认选中单选按钮中的具有某个值的一项
 obj:单选按钮对象
 itemvalue:该项值
 */
 for(i=0;i<obj.length;i++)
 {
  if(obj[i].value==itemvalue)
     obj[i].checked=true;
 }
 
 
}


function checSelectMatchItem(obj,itemvalue)
{
 /*
 默认选中单选按钮中的具有多个值的一项
 obj:单选按钮对象
 itemvalue:该项值
 */
 for(i=0;i<obj.options.length;i++)
 {
  if(itemvalue.indexOf(obj.options[i].value)>=0)obj.options[i].selected=true;
   
 }
 
 
}

 

function seladditem(thevalue,thetext,obj)
{
/*
添加值到下拉列表框
thevalue:值
thetext:显示文本
obj:下拉列表框对象
*/
var oOption = document.createElement("OPTION");
oOption.value=thevalue;
oOption.text=thetext;
obj.add(oOption);
}

function strToDropList(Liststr,obj)
{
   /*
   把图片列表串中的串转为下拉列表
   Liststr:要转换成下拉列表的字符串,用|分隔
   obj:下拉列表框对象
   */
   var nListstr
   nListstr = Liststr.split("|");
   for(i=1;i<nListstr.length;i++)
   {
    seladditem(nListstr[i],nListstr[i],obj);
   }
}

function blRdoChecked(form,sDspStr)  //是否有选择记录
{
 //sDspStr: CheckBox的name  局限于某一部分的CheckBox,不至于影响到其他的CheckBox
 
 var bl=false;
 items=form.all.tags("input");  //检查input输入
 for (i=0;i<items.length;i++)     
  if (items(i).type=="checkbox"&&items(i).name.toUpperCase()==sDspStr.toUpperCase())
   if (items(i).checked)bl=true;
 return bl;
}

function allRdoIDChecked(form,blRadioAllChecked,sDspStr)   //全选-取消函数
{
 //sDspStr: CheckBox的name  局限于某一部分的CheckBox,不至于影响到其他的CheckBox
 
 items=form.all.tags("input");    //取消
 if(blRadioAllChecked)
 {
  for (i=0;i<items.length;i++)
  if (items(i).type=="checkbox"&&items(i).name.toUpperCase()==sDspStr.toUpperCase())
    items(i).checked=false;
  return false;
 }
 else
 {
  for (i=0;i<items.length;i++) //全选 
  if (items(i).type=="checkbox"&&items(i).name.toUpperCase()==sDspStr.toUpperCase())
    items(i).checked=true;
  return true;
 }
}


function openWin(W_name,url,W_top,W_left,W_height,Wwidth,fullscreen)
{
 /*
 打开新窗口
 W_name:窗口名称
 url:窗口地址
 fullscreen:1为全屏,0为不全屏
 */
 switch(fullscreen){
     case 0:
   if(W_name==""){
    window.open(url,"_blank","left="+W_left+", top="+W_top+",height="+W_height+", width="+Wwidth+", toolbar=no , menubar=no, scrollbars=no, resizable=no, location=no, status=no");
   }
   else{
    W_name=window.open(url,"_blank","left="+W_left+", top="+W_top+",height="+W_height+", width="+Wwidth+", toolbar=no , menubar=no, scrollbars=no, resizable=no, location=no, status=no");
   }
   break;
  case 1:
   if(W_name==""){
    window.open(url,"_blank","fullscreen=1");
   }
   else{
    W_name=window.open(url,"_blank","fullscreen=1");
   }
   break;
 }
}

 


function checkAllByName(ElementName,obj)
{
 /*
 利用复选框的Name属性来选择或取消同名的复选框
 ElementName:元素名称
 obj:主导复选框
 */
 var items;
 items=document.getElementsByName(ElementName.toUpperCase());
 if(obj.checked==true)
  for(i=0;i<items.length;i++)
  {
   items[i].checked=true;
  }
 else
  for(i=0;i<items.length;i++)
  {
   items[i].checked=false;
  }
}


function imgInit(picwidth,pichight){
/*
 初始化图片,在body onload里调用
*/
 for(i=0;i<img.length;i++){
  thezoom(img[i],picwidth,pichight);
 }
}

function imgInitbyObject(object,picwidth,pichight){
/*
 初始化图片,在body onload里调用
*/
 for(i=0;i<object.length;i++){
  thezoom(object[i],picwidth,pichight);
 }
}


function thezoom(obj,picwidth,pichight)
{
 //按比例调整图片
 //obj:图片id
 //picwidth:调整后的图片宽度
 //pichight:调整后的图片高度
 var zoom,zoom1,zoom2;
 zoom1=picwidth/obj.width;
 zoom2=pichight/obj.height;
 if(zoom1<zoom2){
  zoom=zoom1;
  obj.height=obj.height*zoom;
  obj.width=picwidth;
 }
 else{
  zoom=zoom2;
  obj.width=obj.width*zoom;
  obj.height=pichight;
 }
 if(obj.width==0){
  obj.width=picwidth;
  obj.height=pichight;
 }
}

//计算选择的个数
function checkCount(aWin,sName){
 var iResult=0;
 var objs=aWin.document.getElementsByName(sName);
 for (i=0;i<objs.length;i++){
  if (objs(i).checked) iResult++;
 }
 return iResult;
}
//读取第一个已选的值
function getCheckedValue(aWin,sName){
 var objs=aWin.document.getElementsByName(sName);
 for (i=0;i<objs.length;i++){
  if (objs(i).checked){
   return objs(i).value;
  }
 }
 return '';
}

//读取已选的值
function getCheckedValues(aWin,sName){
 var checkValue='';
 var objs=aWin.document.getElementsByName(sName);
 for (i=0;i<objs.length;i++){
  if (objs(i).checked){
   checkValue=checkValue+trim(objs(i).value)+",";
  }
 }
 return checkValue;
}


//选择Radio的值
function selRadio(objs,sValue){
 for (var i=0;i<objs.length;i++){
  if(objs[i].value==sValue) {
   objs[i].checked=true;
   break;
  }
 }
}

function showLoading(aWin){
 try{
 var str='';
 str += '<table id="nav_table_Loading_Pre" style="font-size:9pt;POSITION: absolute;border:1px solid gray;left:40%;top:40%;height:50px;width:200px;z-index:2" bgcolor="#FFFFFF"><tr><td align="center">正在载入,请稍候……<br/><img src="../images/loading.gif" alt=""/></td></tr></table>';
 if (!aWin.document.getElementById("nav_table_Loading_Pre")){
  aWin.document.body.insertAdjacentHTML("beforeEnd",str);
 }
 aWin.attachEvent('onload',function () {aWin.document.getElementById("nav_table_Loading_Pre").style.display="none";});
// aWin.attachEvent('onload',new Function('document.getElementById("nav_table_Loading_Pre").style.display="none";'));
 }catch(e){}
// οnlοad="document.getElementById('nav_table_Loading2').style.display='none'"
}

function loadURL(aWin,sURL,sPARAM){
  try{
    var str='';
    str += '<table id="nav_table_Loading" style="font-size:9pt;POSITION: absolute;border:1px solid gray;left:40%;top:'+((parseInt(aWin.document.body.offsetHeight)/2)+parseInt(aWin.document.body.scrollTop)-30)+';height:50px;width:200px;z-index:2" bgcolor="#FFFFFF"><tr><td align="center">正在载入,请稍候……<br/><img src="../images/loading.gif" alt=""/></td></tr></table>';
//    str  = '<table id="nav_table_Loading" style="font-size:9pt;POSITION: absolute;border:1px solid gray;left:40%;top:'+((parseInt(aWin.document.body.offsetHeight)/2)+parseInt(aWin.document.body.scrollTop)-30)+';height:50px;width:140px;z-index:2" bgcolor="#FFFFFF"><tr><td align="center"><img src="../images/appInstall_animated.gif" alt=""/><span style="font:11">正在载入,请稍候</span></td></tr></table>';
    str += '<table style="POSITION: absolute;left:0;top:'+aWin.document.body.scrollTop+';width:100%;height:'+(parseInt(aWin.document.body.offsetHeight)-10)+';z-index:1" ><tr><td align="center"></td></tr></table>';
    if (!aWin.document.getElementById("nav_table_Loading")){
      aWin.document.body.insertAdjacentHTML("beforeEnd",str);
    }
  }catch(e){}
 if (typeof(sURL)=='string'){
  if (sURL!=''){
   if(typeof(sPARAM)=='string'){
       sURL =  sURL+ sPARAM.replace(/&/g,  "%26");;
   }
   aWin.location = sURL;
  }
 }
}


//IP
function ErrIP(obj,sCaption){
 var bIP;
 bIP = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.test(obj.value);
 if (bIP){
  bIP = (RegExp.$1 <= 255) && (RegExp.$2 <= 255) && (RegExp.$3 <= 255) && (RegExp.$4 <= 255);
 }
 if(!bIP){
  showMsg_check(obj,sCaption);
  try{obj.focus();}catch(e){};
  return true;
 }
 return false;
}

function ErrAscii(obj,sCaption){
   var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  var ch;
  var i;
  var temp;
 var str=obj.value;

  for (i=0;i<=(str.length-1);i++){

    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1)
    {
   showMsg_check(obj,sCaption);
   try{obj.focus();}catch(e){};
   return true;
    }
  }
  if (strSource.indexOf(ch)==-1)
  {
   showMsg_check(obj,sCaption);
   try{obj.focus();}catch(e){};
   return true;
  }
  else
  {
    return false;
  }

}

//电子邮件
function ErrEmail(obj,sCaption){
 if(obj.value==null || obj.value=='') return false;
 var bMail;
 bMail = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(obj.value);
 if(!bMail){
  showMsg_check(obj,sCaption);
  try{obj.focus();}catch(e){};
  return true;
 }
 return false;
}

//日期时间
function ErrDateTime(obj,sCaption){
 var bDateTime;
    if(obj.value==null || obj.value=='') return false;
 bDateTime = /^((((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-))(20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/.test(obj.value);
 if(!bDateTime){
  showMsg_check(obj,sCaption);
  try{obj.focus();}catch(e){};
  return true;
 }
 return false;
}
//日期
function ErrDate(obj,sCaption){
 var bDate;
        if(obj.value==null || obj.value=='') return false;
 bDate = /^((((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-))$/.test(obj.value);
 if(!bDate){
  showMsg_check(obj,sCaption);
  try{obj.focus();}catch(e){};
  return true;
 }
 return false;
}

function  showMsg_check(obj,sCaption){
 if (sCaption!==null)
 alert(sCaption);
}

//为空
function ErrEmpty(obj,sCaption,fTarget){
 if (obj.value==''){
  showMsg_check(obj,sCaption,fTarget);
  try{obj.focus();}catch(e){};
  return true;
 }
 return false;
}
//整型
function ErrInteger(obj,sCaption,fTarget){
 if(/^\d+$/.test(obj.value)){
  return false;
 }else{
  showMsg_check(obj,sCaption);
  try{obj.focus();}catch(e){};
  return true;
 }
}
//判断是否是实型
function ErrNumber(obj,sCaption,fTarget){
  if ((/^\d+\.\d+$/.test(obj.value)) || (/^\d+$/.test(obj.value))){
    return false;
  }else{
    showMsg_check(obj,sCaption,fTarget);
    try{obj.focus();}catch(e){};
    return true;
  }
}
 
function ResizeImage(F,D,G){
 var imageObject;
 if(F!=null){
    imageObject=F
  }
  var E=imageObject.readyState;
 if(E!="complete"){
      setTimeout("ResizeImage(null,"+D+","+G+")",50);
      return
   }
 var B=new Image();
 B.src=imageObject.src;
 var A=B.width;
 var C=B.height;
 if(A>D||C>G){a=A/D;b=C/G;
 if(b>a){a=b}A=A/a;C=C/a}
 if(A>0&&C>0){imageObject.width=A;imageObject.height=C}

 function inputkeypress(inputobj){
  if(!inputobj.value.match(/^\d*?\.?\d*?$/))
   inputobj.value=inputobj.t_value;
  else
   inputobj.t_value=inputobj.value;
  if(inputobj.value.match(/^(?:\d+(?:\.\d+)?)?$/))
   inputobj.o_value=inputobj.value
  if(/\.\d\d$/.test(inputobj.value))event.returnValue=false
 }
 function inputkeyup(inputobj){
  if(!inputobj.value.match(/^\d*?\.?\d*?$/))
   inputobj.value=inputobj.t_value;
  else
   inputobj.t_value=inputobj.value;
  if(inputobj.value.match(/^(?:\d+(?:\.\d+)?)?$/))
   inputobj.o_value=inputobj.value
 }
 function inputblur(inputobj){
  if(!inputobj.value.match(/^(?:\d+(?:\.\d+)?|\.\d*?)?$/))
   inputobj.value=inputobj.o_value;
   else{
    if(inputobj.value.match(/^\.\d+$/))
     inputobj.value=0+inputobj.value;
    if(inputobj.value.match(/^\.$/))
     inputobj.value=0;
    inputobj.o_value=inputobj.value
   }
 }

<!--
-->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值