0

在我的 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>  
4

1 回答 1

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
});

​
于 2012-11-17T03:35:53.100 回答