gpt4 book ai didi

javascript - Jquery 对话框打不开?

转载 作者:行者123 更新时间:2023-11-28 05:12:45 25 4
gpt4 key购买 nike

我是 jquery 的新手。我试图在动态 html 内容上制作一个 jquery 对话框。我尝试了两种不同的方式。尽管如此,它不起作用?代码有什么问题。请帮助我。

1 试试 $('#opener').on('click', function(){//action });

2 尝试 $(document).on('click', '#opener', function(){//action });

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Dialog - Animation</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
</head>
<body>
<button id="opener">Open Dialog</button>

<div id="new_dialog_area"></div>
</body>
</html>


<script>

$(function() {

function makedialog(){
var htmlData = '<div id="dialog" title="Basic dialog">';
htmlData += '<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>';
htmlData += '</div>';
$('#new_dialog_area').html(htmlData);
}

// $('#opener').on('click', function(){
$(document).on('click', '#opener', function(){
makedialog();
$("#dialog").dialog({
autoOpen:false,
});
$("#dialog").dialog("open");
});

});
</script>

最佳答案

我认为是另一个错误

change this  'x' to  \'x\'

在第一种情况下,它被视为一个变量

在第二个中,它被视为引号中的简单字符串/字符

htmlData += '<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the \'x\' icon.</p>';
htmlData += '</div>';

演示:jsfiddle

附言继续阅读@J。 C. Rocamonde 的回答:answer

关于javascript - Jquery 对话框打不开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52042487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com