2010-10-27 44 views
15

Tôi không thể thêm nút vào hộp thoại jquery ui này. nếu có thể, vui lòng cho tôi một ví dụ. cảm ơn.Thêm nút vào hộp thoại jquery ui

<script type="text/javascript"> 
    $(document).ready(function() { 
     //setup new person dialog 
     $('#dialog2').dialog({ 
      autoResize: true, 
      show: "clip", 
      hide: "clip", 
      height: 'auto', 
      width: '1000', 
      autoOpen: false, 
      modal: true, 
      position: 'top', 
      draggable: false, 
      title: "انتخاب درخواست", 
      open: function (type, data) { 
       $(this).parent().appendTo("form"); 
      } 
     }); 

     $('#viewfaktor').dialog({ 
      autoResize: true, 
      show: "clip", 
      hide: "clip", 
      height: 'auto', 
      width: '1000', 
      autoOpen: false, 
      modal: true, 
      position: 'top', 
      draggable: true, 
      title: "مشاهده صورت ریز", 
      open: function (type, data) { 
       $(this).parent().appendTo("form"); 
      } 
     }); 


     $('#msgBox').dialog({ 


      autoResize: true, 
      show: "clip", 
      hide: "clip", 
      height: 'auto', 
      width: 'auto', 
      autoOpen: false, 
      modal: true, 
      position: 'center', 
      draggable: false, 



      open: function (type, data) { 
       $(this).parent().appendTo("form"); 
      } 


     }); 



    }); 

    function showDialog(id) { 
     $('#' + id).dialog("open"); 
    } 

    function closeDialog(id) { 
     $('#' + id).dialog("destroy"); 
    } 



</script> 

Trả lời

23
$('#msgBox').dialog({ 
    autoResize: true, 
    show: "clip", 
    hide: "clip", 
    height: 'auto', 
    width: 'auto', 
    autoOpen: false, 
    modal: true, 
    position: 'center', 
    draggable: false, 

    open: function (type, data) { 
     $(this).parent().appendTo("form"); 
    }, 

    buttons: { "OK": function() { $(this).dialog("close"); } } 
}); 
+0

Hãy Xem Câu hỏi của tôi một lần nữa. tôi có lỗi chưa – Shahin

+0

tôi đã thêm mã của bạn nhưng tôi có lỗi cú pháp! – Shahin

+2

Ah. Tôi đã bỏ qua dấu phẩy. Tôi đã cập nhật ví dụ. –

6

Here is an example

thêm video này vào chức năng của bạn:

buttons: { 
       OK: function() { //submit 
        $(this).dialog("close"); 
       }, 
       Cancel: function() { //cancel 
        $(this).dialog("close"); 
       } 
      } 

Vì vậy, bạn sẽ có được

$('#msgBox').dialog({ 


       autoResize: true, 
       show: "clip", 
       hide: "clip", 
       height: 'auto', 
       width: 'auto', 
       autoOpen: false, 
       modal: true, 
       position: 'center', 
       draggable: false, 
       buttons: { 
       OK: function() { //ok 
        $(this).dialog("close"); 
       }, 
       Cancel: function() { //cancel 
        $(this).dialog("close"); 
       } 
      } 
       open: function (type, data) { 
        $(this).parent().appendTo("form"); 
       } 


      }); 
24

Đôi khi bạn muốn thêm các nút tự động sau khi hộp thoại là tạo nên d quá. Xem answer tôi tại câu hỏi Add a button to a dialog box dynamically

var mydialog = ... result of jqueryui .dialog() 
var buttons = mydialog.dialog("option", "buttons"); // getter 
$.extend(buttons, { foo: function() { alert('foo'); } }); 
mydialog.dialog("option", "buttons", buttons); // setter 
+0

Bạn sẽ thêm nút bằng ID cụ thể như thế nào? –

+0

tại sao bạn cần một id trên nút? – JJS

+0

hoặc bạn có nghĩa là thêm nút hiện có được xác định bằng ID không? – JJS

10

Nếu bạn muốn thêm một nút để một hộp thoại mà đã được mở, bạn có thể làm điều gì đó như:

var buttonSet = $('#dialog').parent().find('.ui-dialog-buttonset'); 
var newButton = $('<button>My New Button</button>'); 
newButton.button().click(function() { 
    alert('My new button clicked'); 
}); 
buttonSet.append(newButton); 
Các vấn đề liên quan