如何在特定的jquery验证结构中验证无线电
How to validate radio in specific jquery validation structure
你好,我正在编写一个多步骤表单,并用带有<fieldset> </fieldset>
标签的jquery脚本划分表单的不同部分
我的表单验证在这个脚本上运行,看起来像这个
$(".next").click(function(){
var erros = 0;
//error checking in the first fieldset
if (fieldsetn == 1) {
//verify name
if ($('input[name="name"]').val().length ===0){
$('input[name="name"]').attr("placeholder","Please enter your name");
$('input[name="name"]').addClass('warning');
erros = 1;
}
else {
$('input[name="name"]').removeClass('warning');
}
//verify surname
if ($('input[name="surname"]').val().length ===0){
$('input[name="surname"]').attr("placeholder","Please enter your surname");
$('input[name="surname"]').addClass('warning');
erros = 1;
}
else {
$('input[name="surname"]').removeClass('warning');
}
但我在验证一个无线电场时遇到了一个问题,我的无线电场是这样的:
Chose the Logo pack <a href="services.html" style="float:right" target="_blank">More Information about Logo Packs Pleas click here</a>
<div id="emotion" name="emotion">
<input type="radio" name="emotion" id="basi" />
<label for="basi"><img src="images/basi.jpg" width="630px" alt="I'm sad" /></label><br>
<input type="radio" name="emotion" id="deli" />
<label for="deli"><img src="images/deli.jpg" width="630px" alt="I'm sad" /></label><br>
<input type="radio" name="emotion" id="premi" />
<label for="premi"><img src="images/premi.jpg" width="630px" alt="I'm happy" /></label>
</div>
如何验证我在jquery验证代码结构中设置的单选字段,以便必须选择一个选项?提前感谢
试试这个-
if($('input[name="emotion"]:checked').length==0)
{
alert("Please select radio button");
}
或
if(!$('input[name="emotion"]:checked').length)
{
alert("Please select radio button");
}
演示
这将适用于
if($('input[type="radio"][name="emotion"]').is(':checked'))
{
alert("it's checked");
}else{
alert("it's not checked");
}
if($('input[name="emotion"]:checked').length==0)
{
alert("Please select radio button");
}
这项工作对
if(!$('input[name="emotion"]:checked').length)
{
alert("Please select radio button");
}
相关文章:
- 正在验证8个真/假复选框或复选框中的2个
- 借助asp.net验证或java脚本对多个文本进行验证
- jQuery自定义验证比较多个输入的序列
- 使用html中的外部javascript进行数据验证
- 如何使用jquery Validation验证Formspread
- jquery中的文本框验证
- 在验证和发送邮件后更改联系人表单的 html
- 代码不会验证
- JS验证ajax返回的html中的表单数据
- 同步调用,直到用户通过angular验证为访问者
- 带有加号的电话号码验证(可选)
- 更改JSON对象的结构
- 解析javascript表单验证器
- 两位数的月份日期验证
- javascript和php中的pancard结构验证
- 关于具有用户身份验证的 Web 应用程序的结构
- 需要经过身份验证的 WCF REST 体系结构建议
- Jquery无结构验证不适用于Jquery上的提交事件
- 如何在特定的jquery验证结构中验证无线电
- 在CouchApp文件夹结构中放置自定义验证函数的位置