javascript TypeError 对话框不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32058573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError dialog is not a function
提问by o.o
I need help with this javascript code. I keep getting this error:
我需要有关此 javascript 代码的帮助。我不断收到此错误:
Uncaught TypeError: $(...).dialog is not a function
Code:
代码:
<script>
$(function () {
$('#tdog').dialog({
autoOpen: false,
width: 200,
modal: true,
});
});
</script>
<div id="tdog"></div>
I included the jquery import in the header. What am I doing wrong?
我在标题中包含了 jquery 导入。我究竟做错了什么?
回答by WhiteHat
The script is running before the div has been loaded on the page, thus it is unavailable, add the ready function to ensure it is loaded first.
脚本在页面加载div之前运行,因此不可用,添加ready函数以确保首先加载它。
$( document ).ready(function() {
$('#tdog').dialog({
autoOpen: false,
width: 200,
modal: true,
});
});
回答by Poza Z.
You have to include the ui and also the styles before starting the script
在启动脚本之前,您必须包含 ui 和样式
<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>
回答by Matt Byrnes
In Laravel, I had a minified version of all the js files in /public/js/app.js being included in app.blade.php (main template page). I commented out the inclusion of app.js and the error went away, presumably because of the 'included twice' points made above.
在 Laravel 中,我将 /public/js/app.js 中所有 js 文件的缩小版本都包含在 app.blade.php(主模板页面)中。我注释掉了 app.js 的包含,错误消失了,大概是因为上面提到的“包含两次”点。
回答by eyalap
I'm guessing you forgot to include jquery UI. See this answer for reference: Error: TypeError: $(...).dialog is not a function
我猜你忘了包括 jquery UI。请参阅此答案以供参考: Error: TypeError: $(...).dialog is not a function