Javascript 如何使用户有必要单击按钮以验证表单?

Javascript 如何使用户有必要单击按钮以验证表单?,javascript,html,asp.net-mvc-4,jquery-validate,knockout-mvc,Javascript,Html,Asp.net Mvc 4,Jquery Validate,Knockout Mvc,我有一组按钮,需要单击其中一个按钮才能进入下一个表单: <div class="btn-group" data-toggle="buttons-radio"> <button type="button" class="btn" data-bind="click: sportYes">Yes</button> <button type="button" clas

我有一组按钮,需要单击其中一个按钮才能进入下一个表单:

<div class="btn-group" data-toggle="buttons-radio">
                        <button type="button" class="btn" data-bind="click: sportYes">Yes</button>
                        <button type="button" class="btn" data-bind="click: sportBasic">Basic</button>
                        <button type="button" class="btn" data-bind="click: sportNo">No</button>
                    </div>
即使我知道语法,我也不认为这会有帮助,因为并非所有按钮都是必需的。 有没有办法利用单击我的三个按钮中的一个按钮时呈现的
active
属性?

a
不符合使用此插件进行验证的条件

此插件仅适用于以下八种数据输入元素(每个必须具有唯一的
名称
属性),并且必须包含在表单元素中:

<form>

   <!-- Textbox Input - Also including the various HTML5 input types -->
   <input type="text" name="something" />

   <!-- Password Input -->
   <input type="password" name="pw" />

   <!-- Radio Button -->
   <input type="radio" name="foo" />

   <!-- Checkbox -->
   <input type="checkbox" name="bar" />

   <!-- File Upload -->
   <input type="file" name="upload" />

   <!-- Hidden Input - 'ignore: []' must be defined in the options -->
   <input type="hidden" name="hide" />

   <!-- Select Dropdown -->
   <select name="foobar"> ... </select>

   <!-- Text Area Box -->
   <textarea name="barfoo"></textarea>

</form>
jQuery

<button type="button" class="btn" id="sportYes">Yes</button>
<button type="button" class="btn" id="sportBasic">Basic</button>
<button type="button" class="btn" id="sportNo">No</button>
$(document).ready(function() {

    $("#FormThatNeedsToBeValidated").validate({  // <- initialize plugin on form
        // rules & options
    });

    $('#sportYes').on('click', function() {
        // stuff to do when this button is clicked
        if ($("#FormThatNeedsToBeValidated").valid()) { // <- test validity
            // stuff to do on valid form
            $("#FormThatNeedsToBeValidated").submit();  // <- submit the valid form
        }
    });

    $('#sportBasic').on('click', function() {
        // stuff to do when this button is clicked
    });

    $('#sportNo').on('click', function() {
        // stuff to do when this button is clicked
    });

});
$(文档).ready(函数(){

$(“#需要验证的表单”)。验证({//因此,提交后,我应该使用JS检查其余数据是否有效,以及其中一个按钮是否处于活动状态
?抱歉,延迟。如果3浏览器上的此问题刚刚知道,我必须重新启动:我将尝试您的解决方案。谢谢为什么不使用复选框或单选按钮,而不是按钮?@Barmar我不是该网页的作者或者网站,所以我没有权限更改用户界面。
$(document).ready(function() {

    $("#FormThatNeedsToBeValidated").validate({  // <- initialize plugin on form
        // rules & options
    });

    $('#sportYes').on('click', function() {
        // stuff to do when this button is clicked
        if ($("#FormThatNeedsToBeValidated").valid()) { // <- test validity
            // stuff to do on valid form
            $("#FormThatNeedsToBeValidated").submit();  // <- submit the valid form
        }
    });

    $('#sportBasic').on('click', function() {
        // stuff to do when this button is clicked
    });

    $('#sportNo').on('click', function() {
        // stuff to do when this button is clicked
    });

});