2

我是 jquery 的新手,我想在调用函数时向我的页面添加一个对话框。每当我从控制台调用此函数时,都会显示对话框,但出现以下错误。这是什么意思以及如何解决它?

Uncaught TypeError: a(...).parents(...).andSelf is not a function
    at d (jquery-ui.min.js:5)
    at c (jquery-ui.min.js:5)
    at Array.tabbable (jquery-ui.min.js:5)
    at jquery.min.js:2
    at r (jquery.min.js:2)
    at se.select (jquery.min.js:2)
    at Function.se [as find] (jquery.min.js:2)
    at k.fn.init.find (jquery.min.js:2)
    at a.<computed>.<computed>.open (jquery-ui.min.js:5)
    at a.<computed>.<computed>._init (jquery-ui.min.js:5)

我用过这些 jquery 库:

<script src="../vendor/jquery/jquery.min.js"></script> //Given with my bootstrap theme
<script src="../vendor/jquery-easing/jquery.easing.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

我调用的函数是这个:

function afficherPopupErreur() {
    $('body').append('<div id="dialog" title="Basic dialog"><p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the x icon.</p></div>');
    $( "#dialog" ).dialog();
}

我知道这个附加很奇怪,但它只是为了尝试对话。

4

2 回答 2

2

andSelf已被弃用和删除 - 使用更新的 JQUI

也始终使用 HTTPS 版本

function afficherPopupErreur() {
  $('body').append('<div id="dialog" title="Basic dialog"><p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the x icon.</p></div>');
  $("#dialog").dialog();
}

$(function() {
  afficherPopupErreur();
});
.ui-dialog-titlebar-close { float:right}
.ui-dialog-titlebar-close::after { content:"X" } 
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-bootstrap/0.5pre/assets/css/bootstrap.min.css" />
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

于 2020-03-20T08:07:23.283 回答
1

.andSelf()在 jQuery 1.8 中被弃用并在 jQuery 3.0 中被删除。

.addBack()应该从 jQuery 1.8 开始使用。

尝试在您的代码中将“andSelf”替换为“addBack”

于 2021-02-14T08:38:22.710 回答