web前端界面多对象js验证

当一个表单要多对象提交时,界面的js验证时相当让人烦的事

如果事先有准备的话就会有事半功倍的效果,下面是一个freemarker模板

 <@s.form id="channel_form" name="channel_form" action="" method="post"  theme="simple">
  <table width="682" border="0" cellpadding="0" cellspacing="0">

  <script type="text/javascript">
          function validate_channel(elementValue,elementName){
                <!--elementValue循环的index   elementName 表示每个对象的名称-->
                <!--描述-->
                <!--构造id-->
                var channelDescription="#channelDescription";
                <!--注意:当在js中数字跟字符相拼接时,数字首先要转行成字符才行 -->
                channelDescription+=(elementValue).toString();
                <!--描述的值-->
                var channelDescriptionValue=$(channelDescription).val().replace(/^\s+|\s+$/g, "");
                var channelDescriptionLength=channelDescriptionValue.replace(/[^\x00-\xff]/g, 'xx').length;
                <!--当获取到元素的值和长度时,就可以在界面进行控制和提示了-->
                
                <!-- 数量-->
                var quantity="#quantity";
                quantity+=(elementValue).toString();
                var quantityValue=$(quantity).val();
                <!--跟描述同理-->
            return true;
        }
  </script>
   <#if channelList?exists>
       <#list channelList as channel>
        <#assign index=channel_index/>
  <tr>
    <td height="30">
    <table width="98%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="3%" height="30">&nbsp;</td>
        <td width="15%">描述</td>
        <td width="82%"><@s.textfield name="channelList[${index}].channelDescription" id="channelDescription${index}" size=47/></td>
      </tr>
      <tr>
        <td height="30">&nbsp;</td>
        <td height="30">分配库存量</td>
        <td height="30"><@s.textfield name="channelList[${index}].quantity" id="quantity${index}" /></td>
      </tr>
    </table></td>
  </tr>
    </#list>
   </#if>
  <tr>
    <td height="20" colspan="2" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td height="50" colspan="2" align="center"><label>
     <input type="button" value="保存" class="but02" οnclick="return commit_channel_form();"/>
    </label></td>
  </tr>
</table>
</@s.form> 
 

 

 

注意:如果要把Number转换成String,可以使用Number的toString()方法
(1).toString()括号必须或者 1 .toString()空格必须

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值