TypeError对话框不是函数

时间:2015-08-17 19:52:26

标签: javascript jquery html modal-dialog

我需要这个javascript代码的帮助。我一直收到这个错误:

Uncaught TypeError: $(...).dialog is not a function

代码:

<script>
$(function () {
$('#tdog').dialog({
     autoOpen: false,
     width: 200,
     modal: true,
  });
});
</script>

<div id="tdog"></div>

我在标题中包含了jquery导入。我做错了什么?

4 个答案:

答案 0 :(得分:0)

脚本在页面上加载div之前正在运行,因此它不可用,添加ready函数以确保它首先被加载。

$( document ).ready(function() {
  $('#tdog').dialog({
       autoOpen: false,
       width: 200,
       modal: true,
  });
});

答案 1 :(得分:0)

启动脚本之前,您必须包括用户界面以及样式

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function () {
$('#tdog').dialog({
     autoOpen: false,
     width: 200,
     modal: true,
  });
});
</script>

答案 2 :(得分:0)

在Laravel中,我将/public/js/app.js中所有js文件的简化版本包含在app.blade.php(主模板页面)中。我注释掉了app.js,错误消失了,大概是因为上面提到的“包含两次”这一点。

答案 3 :(得分:-1)

我猜你忘了包含jquery UI。 请参阅此答案以供参考: Error: TypeError: $(...).dialog is not a function

相关问题