2012-01-06 77 views
0

我使用下面的代碼,並決定我想要一個關閉按鈕,而不是超時。JQuery對話框 - 用關閉按鈕替換超時

如何用下面的代碼用關閉按鈕替換超時?

<script type="text/javascript"> 
$(document).ready(function() { 
    $("#info_box").dialog({ 
     autoOpen: false, 
     modal: true, 
      width: 400, 
      zIndex: 9999999, 
     resizable: false, 
     open: function() { 
      // close the dialog 10 secs after it's opened 
      setTimeout(function() { 
       $(this).dialog("close"); 
      }, 10000); 
     } 
    }); 

    $(".notavailable").bind("click", function() { 
     $("#info_box").dialog("open"); 
    }); 
}); 

</script> 
+0

其實你可以刪除'開:函數(){...}'部分 – noob 2012-01-06 14:30:55

回答

3

你只需要一個buttons屬性添加到Objectdialog與創建的,是這樣的:

$("#info_box").dialog({ 
    autoOpen: false, 
    modal: true, 
    width: 400, 
    zIndex: 9999999, 
    resizable: false, 
    buttons: [ 
     { 
      text: "Close", 
      click: function() { 
       $(this).dialog("close"); 
      } 
     } 
    ] 
});