javascript - jquery-ui.js :12443 Uncaught TypeError: Cannot read property 'apply' of undefined

标签 javascript jquery html asp.net-mvc

我在我的项目中编写了这段代码,它显示错误:

Uncaught TypeError: Cannot read property 'apply' of undefined

if (TempData["notice"] != null)
{
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" type="text/css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <p id="dialog" style="color:red">
        @TempData["notice"]<br />
        <button id="bclose">Ok</button>
    </p>
    <script language="javascript">
        $('#dialog').dialog({
          dialogClass: "no-close",
          buttons: [{
            text: "Ok",
            Click: function() {
              $('#dialog').dialog('close');
            }
          }]
        });
    </script>
}

我需要为上述代码添加任何库吗

最佳答案

将您的脚本部分放入:

$(document).ready(function(){
    //your script here
});

类似这样的事情:

<script language="javascript">
   $(document).ready(function(){
     $('#dialog').dialog({
       dialogClass: "no-close",
       buttons: [{
         text: "Ok",
         click: function() {
           $('#dialog').dialog('close');
         }
       }]
     });
   });
</script>

这里正在工作 jsfiddle

关于javascript - jquery-ui.js :12443 Uncaught TypeError: Cannot read property 'apply' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40607033/

相关文章:

javascript - 将某些内容解析为对象文字而不是 block 有什么区别?

javascript - 将隐藏更改为自动溢出属性时避免 SCSS

javascript - 不同功能的 Mocha 测试用例

javascript - 如何在 JavaScript 中将数组转换为字符串

javascript - 需要重新排列 JSON

jquery - 使 DIV 中除其他链接之外的所有元素都充当链接

javascript - 该集合尚未在第二次调用 getEnumeration 时初始化

php - Jquery 查找 div 是否到达滚动底部

html - pre(html 标签) 和 white-space :pre newline omission 之间的区别

javascript - 根据可选路线的不同查询 -expressjs