English 中文(简体)
JQuery审定规则中使用的外地名称变量
原标题:Use field name variable in JQuery validation rules

我是一例。 我可以采用我形式的验证规则。 我正在使用 Java框架,并出于某种原因,当它从xhtml转换到.html时,所有现成的 component/名称都以含有.的形式预先确定。 我想用两种其他形式重复使用这些验证规则,但由于预先确定的问题,我需要使用js变量并通过表格。 职能。 出于某种原因,这给我带来了一个问题:


NOT WORKING

var positionTitle = "#myForm:positionTitle";

$("#" + formId).validate({

  rules:{
        positionTitle : {required:true, maxlength:50},
            ...

WORKING

$("#" + formId).validate({

  rules:{
         "#myForm:positionTitle" : {required:true, maxlength:50},
              ...
最佳回答

在您打电话.validate(>>后,请您:

$("[name= " + positionTitle + " ]").rules("add", {required:true, maxlength:50});

......但你可以把变数作为字面上像这样的物体的名称。

另一种选择是在将<代码>validate(<>/code>>>>通过之前构造<>rules的物体,但只要能产生比喻,我就可以说,根据这个问题,情况较好,但如果你有的话,你可能希望采用<代码>>><>>>> 规则>/代码>。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签