【问题标题】:Strange popup behaviour奇怪的弹出行为
【发布时间】:2011-09-27 21:39:15
【问题描述】:

当我点击“警报”链接时,消息只会弹出一次,这是正确。奇怪的是,如果我单击链接“对话”,然后单击链接“警报”,则消息连续弹出两次,这是不正确

如何解决这个问题,让消息只显示一次?

HTML

<p id="test"><a href="#">alert</a></p>
<a href="#" onclick="showDialog()">dialog</a>

jQuery

$(function() {
  $("p#test a").click(function() {
    alert('alert');
  });
}

function showDialog(){
  $("<div class='popupDialog'>Loading...</div>").dialog({
    closeOnEscape: true,
    height: 'auto',
    modal: true,
    title: 'About Ricky',
    width: 'auto'
  }).bind('dialogclose', function() {
    jdialog.dialog('destroy');
}

【问题讨论】:

    标签: jquery-ui click onclick jquery-ui-dialog


    【解决方案1】:

    你可以试试这个脚本。

    <script type="text/javascript">
    
     $(document).ready(function () {
    
            $("p#test a").click(function () {
                alert('alert');
            });
        });
    
    
        function showDialog1() {
            $("<div class='popupDialog'>Loading...</div>").dialog()({
                closeOnEscape: true,
                height: 'auto',
                modal: true,
                title: 'About Ricky',
                width: 'auto'
            }).bind('dialogclose', function () {
                $(this).dialog('destroy');
            });
        }
    <script> 
    

    【讨论】:

    • 谢谢!我已经用$(document).ready 尝试过了,但没有成功。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 2015-01-12
    • 2011-01-16
    • 2011-07-03
    • 1970-01-01
    • 2020-09-16
    • 2020-11-17
    相关资源
    最近更新 更多