jquery自动完成和jquery验证

时间:2012-11-17 03:23:21

标签: jquery asp.net-mvc jquery-ui jquery-validate jquery-autocomplete

在我的aspx页面上,我正在尝试使用自动填充并验证表单已填写完整。但是,当我同时使用两个库时,无法通过鼠标单击选择自动完成下拉列表,但可以使用箭头并输入键。反正有没有这个问题一起使用这两个包吗?

我从http://jqueryui.com/autocomplete/复制了示例并添加了验证。

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
            <script type="text/javascript"src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
    <script type="text/javascript" src="<%=Url.Content("~/Scripts/jquery.validate.min.js") %>"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#myForm').validate();
            });

            function vaidateForm() {
                if (!$('#QAForm').valid()) return false;
                alert("IS VALID");
            };
        </script>
        <form id="myForm">
            <div id="AssignTo">
                <label for="tags" class="required">Tags: </label>
        <input id="tags" />
            </div>                            
         <input type="button"  onclick="vaidateForm()" value="Save" />
</form>






        <script type="text/javascript">
            $(function () {
                var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
        ];
                $("#tags").autocomplete({
                    source: availableTags
                });
            });
        </script>  

1 个答案:

答案 0 :(得分:0)

请参阅此处:工作演示 http://jsfiddle.net/G3Qqc/1/

验证插件:http://docs.jquery.com/Plugins/Validation

这应符合您的原因:)

<强>代码

$(document).ready(function(){
    $("#registerForm").validate();
});


$( "#tags" ).autocomplete({
    source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ],
    delay: 0
});

​