2009-09-14 92 views
1

我想在Simplemodal打開窗口時執行一個函數,並用回調函數填充'onShow'字段。在下面的例子中,我只填寫了一個警告提示,也就是每次打開簡單窗口時警報應該會觸發。jquery + Simplemodal onshow方法只執行一次

但是,看起來這只是被執行一次。如果模式打開,然後關閉,然後重新打開,重新打開後,此方法不會在後續打開時調用。

請剪切和粘貼下面的HTML文檔中看到這種行爲(關閉模式窗口,然後單擊打開模式窗口按鈕)

我缺少什麼,讓昂秀每次執行窗口打開了?

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 

<link type="text/css" href="ttp://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" /> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script> 
    <script src='http://www.ericmmartin.com/simplemodal/js/jquery.simplemodal.js' type='text/javascript'></script> 
    <script src='http://www.ericmmartin.com/simplemodal/js/basic.js' type='text/javascript'></script> 


    <link type='text/css' href='ttp://www.ericmmartin.com/simplemodal/css/basic.css' rel='stylesheet' media='screen' /> 



<script type="text/javascript"> 


$().ready(function() { 

    $('#basic-modal input.basic, #basic-modal a.basic').click(function (e) { 
     e.preventDefault(); 
     $('#basic-modal-content').modal(); 
    }); 

    $('#basic-modal-content').modal({onShow: 

    function(dialog) { 
    alert('hello'); 


}}); 



}); 

</script> 
</head> 

<body> 

    <div id='basic-modal-content'> 
    <input type="text" id="amount" style="border:0; color:#ffffff; font-weight:bold; width: 40px; background: #aaaaaa;" /> 
    <div id="slider-vertical" style="height:200px;"></div> 
    </div> 

    <div id='basic-modal'> 
    <h2>Basic Modal Dialog</h2> 
     <form action='download/' method='post'> 
      <input type='button' name='basic' value='Show modal' class='basic demo'/> 
     </form> 
    </div> 
</body> 

回答

2

您需要刪除您從我的網站加載的basic.js。這與您的代碼衝突。

+0

謝謝你,會試試這個。 – folder 2009-09-21 23:13:22

0

我想你想使用每次調用模態時的onShow選項。

$('#basic-modal input.basic, #basic-modal a.basic').click(function (e) { 
    e.preventDefault(); 
    $('#basic-modal-content').modal({ 
     onShow: function(dialog) { 
     alert('hello'); 
     } 
    }); 
}); 
+0

在上面的代碼中,我從來沒有看到警報被解僱。 – folder 2009-09-15 00:06:20

+0

你確定點擊事件被解僱嗎? – 2009-09-15 00:09:49

+0

是的,因爲如果我將代碼更改爲以下內容,將觸發第一個警報: $('#basic-modal input.basic,#basic-modal a.basic')。click(function(e){ 。警報( '點擊解僱'); e.preventDefault(); $( '#基本模態的內容')模態( {昂秀: 功能(對話){ 警報( '你好'); }} ); }); – folder 2009-09-15 00:13:34