2011-09-27 95 views
1

當我點擊鏈接'提醒'時,郵件將只彈出一次,這是正確。奇怪的是,如果我點擊鏈接「對話框」,然後在鏈接「提醒」,然後消息連續彈出兩次,這是不正確奇怪的彈出行爲

我該如何解決這個問題,讓消息只顯示一次?

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'); 
} 

回答

0

你可以試試這個腳本。

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

謝謝!我已經用'$(document).ready'試過了,但沒有成功。 – shub