Java HTML输入表单名称

时间:2011-09-03 13:59:27

标签: java html forms input

我有这些表单字段,其名称如下:

  

/dwint/singlepagecheckout/DWINTOneClickCheckoutFormHandler.bean.shippingAddress.firstName

我试图传入jQuery验证,但得到各种错误。有没有人有任何建议?

 $("#temp2_form").validate({
    rules: {
      email: {
        required: true,
        email: true
      },  
      /dwint/singlepagecheckout/DWINTOneClickCheckoutFormHandler.bean.shippingAddress.firstName: {
        required: true
      }    
    }
  });

1 个答案:

答案 0 :(得分:1)

那是因为.在JavaScript中具有特殊含义。幸运的是,这可以通过简单地使用字符串查找而不是直接赋值来修改。尝试:

// you might also want to get the name attribute from the element itself
var firstName = '/dwint/singlepagecheckout/DWINTOneClickCheckoutFormHandler.bean.shippingAddress.firstName'

var validRules = {
  rules: {
    email: {
      required: true,
      email: true
    }
  }
}

validRules[firstName]={required:true}
$("#temp2_form").validate(validRules)