Validate inputs that are not inside a form with jQuery Validation plugin [closed]

孤人 提交于 2019-12-17 12:31:17

问题


How can I validate some inputs that are not inside a form tag?

All the samples I found have a form tag, but I want to validate some inputs that are not inside a form.


回答1:


The previously accepted answer (since deleted) was linking to a plugin that was last updated in January 2009. This obsolete plugin is very different than the plugin the OP was asking about:

Title: "Validate inputs that are not inside a form with jQuery Validation plugin"

Tag: jquery-validate

Using the jQuery Validate plugin, you cannot validate input elements that are contained outside of a <form></form> container. There is no workaround for this limitation.

DEMO 1: Shows the proper usage with a form container.

<form id="myform">
    <input type="text" name="myinput" />
    <input type="submit" />
</form>

http://jsfiddle.net/nswnomn6/


DEMO 2: Shows the form container changed into a div and the same code is now totally broken. The plugin does nothing without a form container.

<div id="myform">
    <input type="text" name="myinput" />
    <input type="submit" />
</div>

http://jsfiddle.net/nswnomn6/1/


Your only alternative would be to use a different jQuery plugin for form validation. Unfortunately, I know of no jQuery form validation plugin that would allow you to validate input elements outside of a <form> container.




回答2:


Provided we're talking about the same validation plug-in, I don't think it's possible.

I think the requirements for the plug-in dictate that the items to be validated are inside a form.

You could always try replacing the form with a div in a sample page...



来源:https://stackoverflow.com/questions/487430/validate-inputs-that-are-not-inside-a-form-with-jquery-validation-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!