jquery中所有字段的表单验证不起作用

时间:2017-01-08 05:30:07

标签: jquery

我使用jQuery Validation Plugin来验证我的表单,即“用户表单”。当我尝试使用valid()方法验证它时,即使填充了单个输入字段,它也会返回true。

        var questions = ['Dog on plane', 'cat in train', 'the turtle', 'the slug', 'the sloth', 'where is', 'Waldo?', 'over there', 'Where?', 'hes gone'];
        var options = [ 
            'Select an Option',
            {
                val: 1,
                text: "1 (strongly agree)"
            },
            {
                val: 2,
                text: "2"
            },
            {
                val: 3,
                text: "3"
            },
            {
                val: 4,
                text: "4"
            },
            {
                val: 5,
                text: "5 (dont agree at all)"
            }
        ];

        var nameLabel = $('<label for="name">' + "Your Name" + '</label>' + '<br>');
        $('.rForm').append(nameLabel);
        var namePut = $('<input type="text" id="name" placeholder="Name">' + '<br>' + '<br>');
        $('.rForm').append(namePut);
        var photo = $('<label for="link">' + "Your Photo Link" + '</label>' + '<br>');
        $('.rForm').append(photo);
        var photoPut = $('<input type="text" id="link" placeholder="Your Photo Link">' + '<br>' + '<br>');
        $('.rForm').append(photoPut);

        for(var x = 0; x < questions.length; x++)
        {
            //x starts at 1 for some reason. First question should be dog one but it starts at cat question
            var div = $('<div class="containter">');
            var h3 = $('<h3 style="margin-bottom: 5px;">' + "Question" + " " + x + '</h3>');
            $(div).append(h3);
            var label = $('<label>').attr('id', 'q'+ x).text(questions[x]);
            var br = $('<br>');
            $(div).append(label);
            $(div).append(br);
            var select = $('<select>').attr('id', 'q'+ x);

            for(var i = 0; i < options.length; i++)
            {
                if(i === 0){
                    select.append($('<option>').text(options[i]));
                }
                else{
                    select.append($('<option>').attr('value', options[i].val).text(options[i].text));
                }

                console.log('hi')
            }
            $(div).append(select);

            $('.rForm').append(div);
        }

如何解决此问题,使其仅在填写完所有字段后才会生效?

1 个答案:

答案 0 :(得分:1)

根据the docs,您需要先在表单上调用cv2.imshow()方法,然后才能使用mul_img = mul_img.astype(np.uint8) 。所以,例如:

validate()