jQuery 验证插件:我有多个图像,需要选择一张图像
我正在使用 jQuery 验证插件,但我的表单包含某种图像选择器,如果选择了一张图像,我需要验证它。但我不知道 jQuery 验证插件是否可以。下面是代码片段:
<div id="options">
<h1>Type</h1>
<ul>
<li>
<p><a href="#"><img src="../images/general/option1.png" /></a>option1</p>
</li>
<li>
<p><a href="#"><img src="../images/general/option2.png" /></a>option2</p>
</li>
<li>
<p><a href="#"><img src="../images/general/option3.png" /></a>option3</p>
</li>
<li>
<p><a href="#"><img src="../images/general/option4.png" /></a>option4</p>
</li>
</ul>
</div>
How do I validate this in jQuery 验证插件?
I'm using jQuery validation plugin, but my form includes some kind of image selector, and I need it to be validated if one image is selected or not.. but i dont know if it's possible in jQuery validation plugin. Here's the snippet of code:
<div id="options">
<h1>Type</h1>
<ul>
<li>
<p><a href="#"><img src="../images/general/option1.png" /></a>option1</p>
</li>
<li>
<p><a href="#"><img src="../images/general/option2.png" /></a>option2</p>
</li>
<li>
<p><a href="#"><img src="../images/general/option3.png" /></a>option3</p>
</li>
<li>
<p><a href="#"><img src="../images/general/option4.png" /></a>option4</p>
</li>
</ul>
</div>
How do I validate this in jQuery validation plugin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@Kevin Lee,检查这个 Jquery 插件
http://jordankasper.com/jquery/imagecheck/examples.php
你只需要将此插件应用到单选/复选框组(根据需要),并为图像相关的单选/复选框输入字段设置验证“必需”。你的所有代码都应该在标签 ie
和 javascript
中,只是为了给你和想法希望这会有所帮助:)
@Kevin Lee , check this Jquery plugin
http://jordankasper.com/jquery/imagecheck/examples.php
you just need to apply this plugin in to radio/checkbox group (as required) and set validation "required" for the image related radio/checkbox input field . And your all code should be within the tag i.e
And javascript
just to give u and idea hope this will be helpful :)
您可以将图像选择视为一组单选按钮输入,并使用 jQuery 验证来要求检查其中一个。请参阅此网站:http://ryanfait.com/resources/custom-checkboxes- and-radio-buttons/ 有关如何使用图像作为单选按钮的示例。
如果要添加对多项选择的支持,可以使用复选框而不是单选按钮。
You can treat the image selection as a set of radio button inputs, and use jQuery Validation to require one of them to be checked. See this site: http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/ for an example of how to use images as radio buttons.
If you want to add support for multiple selections, you can use checkboxes instead of radio buttons.
我认为你最好的选择是根据你所说的内容使用一些自定义代码。如果您已经有一个限制器来确保只有一张图像具有选定的类别,只需运行 $(".whatever") 并检查长度是否等于 1。只有 3 行代码。
I think your best bet is to just use some custom code based on what you've said. If you already have a limiter to ensure that there is only one image with a selected class, simply run a $(".whatever") and check if the length is equal to one. It's only 3 lines of code.