3

对于此示例,我只有一个具有必需属性的输入字段,即使 iOS Safari(iPhone/iPad)和 IE9 上的值为空,我也会收到警报。Firefox 和 Chrome 运行良好。

我错过了什么?

<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
        <title>jqBootstrapValidation by ReactiveRaven</title>

        <link rel="stylesheet" href="http://reactiveraven.github.com/jqBootstrapValidation/css/bootstrap.css">
        <script src="http://reactiveraven.github.com/jqBootstrapValidation/js/jQuery-1.7.2-min.js"></script>
        <script src="http://reactiveraven.github.com/jqBootstrapValidation/js/bootstrap.js"></script>
        <script src="http://reactiveraven.github.com/jqBootstrapValidation/js/jqBootstrapValidation.js"></script>

        <script>
            $(function() {
                $("input,textarea,select").jqBootstrapValidation(
                    {
                        preventSubmit: true,
                        submitError: function($form, event, errors) {
                            // Here I do nothing, but you could do something like display 
                            // the error messages to the user, log, etc.
                        },
                        submitSuccess: function($form, event) {
                            alert("OK");
                            event.preventDefault();
                        },
                        filter: function() {
                            return $(this).is(":visible");
                        }
                    }
                );
            });
        </script>

    </head>
    <body>
    <div class="tabbable">
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="#validators_required_preview">Example</a></li>
        </ul>
        <div class="tab-content">
            <div id="validators_required_preview" class="tab-pane active">
                <form class="form-horizontal">
                   <input name="some_field" required="" value="" type="text">
                   <button type="submit" class="btn btn-primary">Test Validation <i class="icon-ok icon-white"></i></button></form>
            </div>
        </div>
    </div>
</body></html>
4

2 回答 2

1

您必须将输入字段包含在具有“控制组”类的 div 中

<div class="control-group">
<input name="some_field" required="" value="" type="text">
<p class="help-block"></p>
</div>
于 2013-09-07T11:38:37.510 回答
0

只是一个简短的说明。尽管在 IE 和 safari 中缺乏对“必需”属性的支持,这现在仍然有效。这里的信息: http ://reactiveraven.github.com/jqBootstrapValidation/

于 2013-04-03T14:22:05.403 回答