Jquery - 多级数组的单选按钮验证

时间:2018-01-10 07:44:56

标签: jquery arrays validation multidimensional-array radio-button

我正在尝试将验证添加到多维单选按钮,但我对如何在此添加验证感到困惑。下面是单选按钮的图像

在提交时,我需要验证单选按钮。单选按钮是使用循环动态添加的,我尝试了vailidating但这不起作用。我从here

那里得到了一些帮助

问题

<form id="quiz-new" method="POST" action="php/updatequiz.php" runat="server" enctype=multipart/form-data>
   <div class="txt-box">
     <input type="text" name="quiz[1][ques_title]">
     <input type="file" placeholder="Add Media" name="quiz[1][ques_image]" class="quiz-img-preview">
     <input type="radio" name="quiz[1][is_right]" value="392">
     <input type="radio" name="quiz[1][is_right]" value="393">
     <input type="radio" name="quiz[1][is_right]" value="394">
     <input type="radio" name="quiz[1][is_right]" value="395">
   </div>
   <div class="txt-box">
     <input type="text" name="quiz[2][ques_title]">
     <input type="file" placeholder="Add Media" name="quiz[2][ques_image]" class="quiz-img-preview">
     <input type="radio" name="quiz[2][is_right]" value="396">
     <input type="radio" name="quiz[2][is_right]" value="397">
     <input type="radio" name="quiz[2][is_right]" value="398">
     <input type="radio" name="quiz[2][is_right]" value="399">
   </div>
  <input type="submit" value="Create Quiz" class="create-quiz">
</form>

FOOTER

$('#quiz-new').validate();

var ques_title = $('input[name^="quiz"]');

ques_title.filter('input[name$="[ques_title]"]').each(function() {
    $(this).rules("add", {
        required: true,
        messages: {
            required: "Title is Mandatory"
        }
    });
});

0 个答案:

没有答案