javascript - 未捕获的类型错误 : undefined is not a function

标签 javascript jquery

我不断收到自动完成功能未捕获的类型错误。 然而,我在另一个jsp上有完全相同的代码,但那个工作得很好...... 当我使用自动完成功能时,有什么事情是我绝对记得的吗?

   <title>Insert title here</title>
<script type="text/javascript"  src="http://code.jquery.com/jquery-1.10.2.js"></script>
<link rel="stylesheet"  href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet"  href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script type="text/javascript">
    $(function() {

        $("#med_name").autocomplete({
            source : function(request, response) {
                $.ajax({
                    url : "${pageContext.request.contextPath}/searchMed.do",
                    data : {
                        search : $("#med_name").val()
                    },
                    dataType : "json",
                    type : "post",
                    success : function(jsonData) {
                        response($.map(jsonData.medlist, function(item) {
                            return {
                                value : item.imed_name,
                                label : item.imed_name,
                                id : item.imed_id,
                                dos : item.imed_dos,
                                img : item.imed_img
                            };
                        }));
                    }
                })
            },
            select : function(event, ui) {
                alert(ui.item.img);
                $("#med_imed_id").val(ui.item.id);
                $("#med_dos").val(ui.item.dos);
                $("#med_img").attr("src", "medimg/" + ui.item.img);
            },
            selectFirst : false,
            minLength : 1,
            focus : function(event, ui) {
                $('#med_name').val(ui.item.label);
                return false;
            },
        });
});

上面是js部分 下面是jsp部分

 <table>
            <tr>
                <th colspan="2">Prescription</th>
            </tr>
            <tr>
                <th>Medication</th>
                <td><input type="text" id="med_name" name="med_name"/><input
                    type="hidden" id="med_imed_id" name="med_imed_id" value="" /></td>
            </tr>
            <tr>
                <th>Dose</th>
                <td><input type="text" id="med_dos" name="med_dos" /></td>
            </tr>
            <tr>
                <td colspan="2"><img src="" alt="" id="med_img" name="med_img"/></td>
            </tr>
            <tr>
                <td colspan="2"><input type="button" id="addBnt" name="addBnt"
                    value="add" /></td>
            </tr>
        </table>

最佳答案

您能否确认 Jquery UI 是否正确加载?我检查了该链接并包含自动完成功能,它应该可以工作。同时删除这些 Jquery 调用之一。谢谢!

关于javascript - 未捕获的类型错误 : undefined is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23992183/

相关文章:

javascript - 可靠的文本框自动完成方法

php - 来自 Moodle 插件的调试信息

javascript - 更改其属性后渲染数组项

javascript - 如何在悬停时显示进度条?

jquery 根据列值高亮行

javascript - 我可以使用什么将 YouTube 视频的链接存储到我的页面中?

php - 放入正文

javascript - 没有 Index.html 设计的登录页面 - ngRoute (AngularJS)

javascript - 模块模式的技巧

javascript - 在一个点停止一个位置固定的div