javascript - jQuery 对话框 - X 按钮未显示

标签 javascript jquery html jquery-ui bootstrap-4

我正在测试 bootstrap 和 jQuery 是否可以正常工作,但 jQuery 对话框的 X 按钮没有显示。

我认为这与标签顺序有关。

这是我的代码:

$(function () {
    $("#dialog").dialog();
});
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="js/jqueryTheme.css">
    <link rel="stylesheet" href="css/style.css">

</head>
<body>

    <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>



    <!-- jQuery --> <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
    <!-- jQueryUI --> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
    <!-- Bootstrap --> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    <!-- Custom jQuery --> <script type="text/javascript" src="js/jQuery.js"></script>
</body>
</html>

最佳答案

要实现此对话框,您需要在代码中添加jQueryUI CSS

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Document</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
</head>
<body>
 
<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>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script>
$( function() {
  $( "#dialog" ).dialog();
} );
</script>
 
</body>
</html>

关于javascript - jQuery 对话框 - X 按钮未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56491895/

相关文章:

javascript - 如何通过 handlebar.js 创建度数符号?

jquery - 使用ajax加载框架

javascript - 如何使用 javascript 函数为每个 div 分配一个坐标值?

javascript - 如何将快速路由处理传递给下一个中间件并破坏当前的代码块?

javascript - jQuery/JavaScript : Autopopulate Dynamically Populated Elements

javascript - 在 ng-repeat 中添加新的输入字段

javascript - e.stopPropagation() 没有按预期工作?

javascript - 将事件绑定(bind)到数组中的选择器

javascript - html 的非硬编码 <option>,而是让 <option> 显示本地文件

javascript - html 如何将用户字段输入作为 json 对象发送