gpt4 book ai didi

javascript - 如何在链接点击时显示jquery对话框

转载 作者:行者123 更新时间:2023-12-02 22:46:36 25 4
gpt4 key购买 nike

我希望在单击导航菜单中的特定链接时弹出一个带有确认信息的jquery。我有下面的代码,但弹出窗口没有出现,但弹出窗口上的信息显示在页面上其他页面内容。

HTML 链接

<li><a href="#" id="order" target="_blank">Order </a></li>

对话框内容

<div id="dialog-confirm"> 
<div class="message">UI Content goes here</div>
<div class="buttons">
</div>

jquery

 <script>
$( function() {
$( "#dialog-confirm" ).dialog({
$( "#order").click({
resizable: true,
height: "auto",
width: 600,
modal: true,
buttons: {
"Yes": function() {
window.location.replace("https://link_here");
},
No: function() {
window.location.replace("https://link_here");
}
}
});
});
} );

当我删除$( "#order").click({时作为jquery的一部分,它作为每个点击链接的弹出窗口,所以问题一定存在,但我无法解决。

最佳答案

点击前有调用对话框功能请检查以下代码

$(function(){
$('#order').click(function(e){
e.preventDefault();
$( "#dialog-confirm" ).dialog({
resizable: true,
height: "auto",
width: 600,
modal: true,
buttons: {
"Yes": function() {
window.location.replace("https://link_here");
},
No: function() {
window.location.replace("https://link_here");
}
}
});
})

})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />
<li><a href="#" id="order">Order </a></li>

<div id="dialog-confirm" style="display: none;">
<div class="message">UI Content goes here</div>
<div class="buttons">
</div>

关于javascript - 如何在链接点击时显示jquery对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58378793/

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