校验并记忆之前填过的数据 xslt

鼠标离开input框进行校验,点击则显示之前填过的数据。

在input中添加backValue属性用于记录value属性中的值。

stack用于记录是否还有错误存在。

以下代码来自xslt文件中的代码片段

<script language="JavaScript" type="text/javascript">
     var stack=0;
     function updateContract(){
      if(stack=="0"){
       document.getElementById("frm").action="updateContract.action";
       document.getElementById("frm").submit();
      }
     }
     function submitContract(){
      document.getElementById("frm").action="submitContract.action";
      document.getElementById("frm").submit();
     }
     function validData(inputName){
       var inputObj=document.getElementsByName(inputName);
       if(inputObj[0].ismust=="1"){
        if(inputObj[0].value!=""){
         inputObj[0].backValue=inputObj[0].value;
        }else{
         inputObj[0].value="必填项";
         inputObj[0].backStyle=inputObj[0].style.cssText;
         inputObj[0].style.cssText=inputObj[0].style.cssText+";BACKGROUND-COLOR:RED;";
         stack++;
         return;
        }
       }
       if(inputObj[0].value!=""){
        if(inputObj[0].itemType=="2"){
         if(!(inputObj[0].value+'').match(/^\d+\.{0,1}\d+$/)){
          inputObj[0].backValue=inputObj[0].value;
          inputObj[0].value="只能填入数字";
          inputObj[0].backStyle=inputObj[0].style.cssText;
          inputObj[0].style.cssText=inputObj[0].style.cssText+";BACKGROUND-COLOR:RED;";
          stack++;
          return;
         }
         if(!!(inputObj[0].value+'').match(/^\d+\.{0,1}\d+$/)){
          if(inputObj[0].value.length&gt;inputObj[0].length){
           inputObj[0].backValue=inputObj[0].value;
           inputObj[0].value="只能输入"+inputObj[0].length+"个数字";
           inputObj[0].backStyle=inputObj[0].style.cssText;
           inputObj[0].style.cssText=inputObj[0].style.cssText+";BACKGROUND-COLOR:RED;";
           stack++;
           return;
          }
         }
        }
       }
       stack--;
     }
     function resetData(inputName){
      var inputObj=document.getElementsByName(inputName);
      inputObj[0].style.cssText=inputObj[0].backStyle;
      inputObj[0].value=inputObj[0].backValue;
     }
    </script>

 

  

  <xsl:template match="INPUT">
  <xsl:element name="input">
   <xsl:attribute name="type">text</xsl:attribute>
   <xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute>
   <xsl:attribute name="length"><xsl:value-of select="./@size"/></xsl:attribute>
   <xsl:attribute name="ismust"><xsl:value-of select="./@ismust"/></xsl:attribute>
   <xsl:attribute name="itemType"><xsl:value-of select="./@itemType"/></xsl:attribute>
   <xsl:attribute name="id">inputId</xsl:attribute>
   <xsl:attribute name="backValue"><xsl:value-of select="."/></xsl:attribute>
   <xsl:attribute name="style">border:1px; border-bottom-style: solid;border-top-style: none;border-left-style:none;border-right-style:none;</xsl:attribute>
   <xsl:attribute name="backStyle">border:1px; border-bottom-style: solid;border-top-style: none;border-left-style:none;border-right-style:none;</xsl:attribute>
   <xsl:attribute name="onblur">validData('<xsl:value-of select="./@name"/>')</xsl:attribute>
   <xsl:attribute name="onfocus">resetData('<xsl:value-of select="./@name"/>')</xsl:attribute>
   <xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>
  </xsl:element>
 </xsl:template>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值