选择选项的jQuery验证
我在尝试验证表单时遇到了一些问题 用户必须选择“标题”、“徽标”和每个标题的值。现在它不会验证,即使我已经选择了所有的 JS小提琴: Javascript:选择选项的jQuery验证,jquery,validation,html-select,Jquery,Validation,Html Select,我在尝试验证表单时遇到了一些问题 用户必须选择“标题”、“徽标”和每个标题的值。现在它不会验证,即使我已经选择了所有的 JS小提琴: Javascript: $().ready(function(){ $('.test').hide(); $(".header, .logo").on("click",function(){ var relatedSelect2 = $(this).parent('.parent').children('.test'); $('.test').hide()
$().ready(function(){
$('.test').hide();
$(".header, .logo").on("click",function(){
var relatedSelect2 = $(this).parent('.parent').children('.test');
$('.test').hide();
$('.parent').each(function(index){
$(this).children('input:checked').parent('.parent').children('.test').show();
});
relatedSelect2.show();
});
jQuery('#submit').click(function(event){
if( $("input[name='header']:checked").length > 0 && $("input[name='logo']:checked").length > 0 && $('#image_option > option:selected').length != 0 ) {
alert('Updated!');
}
else if( $("input[name='header']:checked").length == 0 && $("input[name='logo']:checked").length == 0 && $('#image_option > option:selected').length == 0 ) {
alert('Please select a header and logo and template for each');
return false;
}
else if( $("input[name='header']:checked").length > 0 && $("input[name='logo']:checked").length == 0) {
alert('Please select a logo');
return false;
}
else if( $("input[name='header']:checked").length == 0 && $("input[name='logo']:checked").length > 0) {
alert('Please select a header');
return false;
}
else if( $("input[name='header']:checked").length > 0 && $("input[name='logo']:checked").length > 0 && $('#image_option > option:selected').length == 0 ) {
alert('Please select a template');
return false;
}
else if( $("input[name='header']:checked").length == 0 && $("input[name='logo']:checked").length == 0 && $('#image_option > option:selected').length != 0 ) {
alert('Please select a header and logo');
return false;
}
});
});
请先修复你的HTML。ID必须是唯一的,目前无法为所有3个选择选择某个内容,因为具有名称的那些具有相同的名称。我需要它,以便他们只能选择2个,但一旦选择了标题、徽标和选项,“选择模板”将显示错误。让我看看我是否正确理解您的意思。您希望确保用户必须选择“标题”、“徽标”、“选项”。我说得对吗?你看过jQuery验证了吗?是的,我唯一的问题是必须选择第一个select下拉列表才能提交表单,但是我需要表单删除任何标题和徽标,只要它们都选择了选项。