jQuery和jVal验证插件。添加属性到一个元素 [英] jQuery and jVal Validation Plug-in. Adding an attribute to an element

查看:245
本文介绍了jQuery和jVal验证插件。添加属性到一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给jVal属性添加到我的HTML创建一个文本框。

I'm trying to add the jVal attribute to a textbox that I created in the HTML.

<input id="subJobName" type="text" jval="{valid:function (val) { return validateSubJobName(val); }, message:'Name already exists or is longer than 14 characters.', styleType:'cover'}" />

我先给添加/设置jVal在JavaScript来代替。

I would let to add /set the jVal in the javascript instead.

2的原因 -

1:我不会需要搜索的HTML看到每一个项目是如何验证

1st : I will not need to search the HTML to see how each item is validated

第二:我们正在使用的jqGrid和我想此验证添加到每个文本框为动态创建

2nd : We are using a jqGrid and I would like to add this validation to each text box as its dynamically created.

我想我将能够删除从HTML的jVal离开我与普通的旧文本框。

I thought I would be able to removed the jVal from the HTMl to leave me with plain old text box.

<input id="subJobName" type="text" />

然后在Doc.Ready功能我想添加jVal到SubJobName元素,像这样:

Then in the Doc.Ready function I'd add the jVal to the SubJobName element like so:

$("#subJobName").attr({ jval: { valid: function(val) { return validateSubJobName(val); }, message: "Nam", styleType: "cover"} });

这是行不通的。我不知道如果我甚至可以这样做吗?任何人有什么想法?

This doesn't work. I'm not sure if I can even do this ? Anyone have any ideas?

感谢

推荐答案

我jVal 0.1.4进行中的工作,这增加了一个init()函数为你在找什么。 // jquery-:从 HTTP取jVal.js最新行李箱jval.google code.com / SVN /主干/ jVal.js

I have jVal 0.1.4 as a work in progress which adds an init() function for what you're looking for. Fetch the latest trunk of jVal.js from http://jquery-jval.googlecode.com/svn/trunk/jVal.js.

您可以附加jVal和jValKey属性字段,然后这样重新初始化jVal功能:

You can append the jVal and jValKey attributes to fields and then re-initialize the jVal functionality as such:

$("#subJobName").attr({ jval: { valid: function(val) { return validateSubJobName(val); }, message: "Nam", styleType: "cover"} });
$.fn.jVal.init();

这篇关于jQuery和jVal验证插件。添加属性到一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆