关闭 jQuery 对话框


Closing jQuery dialog

出于某种原因,我让这段代码像弹出窗口一样显示。

<div id="myDialog" title="myTitle">
  <div class="table_cell">
    <div class="message"></div>
  </div>
  <div class="table_cell" onclick="doMyThing(<?php echo $id; ?>)">
    <span style="cursor:pointer">Accept</span>
  </div>
</div>

当我使用 Javascript 触发某个事件时,将执行下一个代码:

$(document).ready(function() {
    $('#myDialog').dialog();
    $('.message').html("Some text");
});

这工作得很好。虽然,我需要在单击我的跨度字段后隐藏/关闭对话框。我已经尝试过类似$('#myDialog').dialog('close');的东西,但它不起作用。另外,尝试在第一次单击然后display: nonedisplay: block"myDialog",但对话框仍然保留在屏幕上。

这个"myDialog"实际上是从css接收一些风格,这就是为什么我要编写这样的假对话框。有什么建议吗?

您可以使用提供的按钮,而不是制作自己的按钮

j查询:

$(document).ready(function() {
    $( "#mydialog" ).dialog({
       modal: true,
       buttons: {
         "Accept": function() {
              doMyThing(<?= $id ?>);
              $( this ).dialog( "close" );
            }
       }
    })
});

.HTML:

<div id="myDialog" title="myTitle">
 <div class="table_cell">
  <div class="message"></div>
 </div>
</div>

您可以在此处查看正确的文档:http://jqueryui.com/dialog/#modal-confirmation

在此处查看链接

<div id="dialog-confirm" title="Empty the recycle bin?">
  <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
 <script>
  $(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "Delete all items": function() {
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });
  </script>

.dialog('close')应该可以正常工作。正确引用跨度。

<div id="myDialog" title="myTitle">
  <div class="table_cell">
    <div class="message"></div>
  </div>
  <div class="table_cell" onclick="doMyThing(<?php echo $id; ?>)">
    <span id='accept' style="cursor:pointer">Accept</span>
  </div>
</div>
$(document).ready(function() {
    $('#myDialog').dialog();
    $('.message').html("Some text");
    $('#accept').on('click', function(){
         $('#myDialog').dialog('close');
    })
});

在这里摆弄

好吧,我终于使用了jQuery按钮并改变了它的外观。我试图在那里使用 css 类,但没有成功。

$(document).ready(function() {
            $('.message').html("Some text");
            $( '#myDialog' ).dialog({
                modal: true,
                buttons: {
                    'accept': {
                        style:'background:#D1040E; color: #DADADA',
                        text: 'Accept',
                        click: function() {
                            doMyThing(<?php echo $id; ?>);
                            $( this ).dialog( 'close' );
                        }
                    },
                    'cancel': {
                        style:'background:#D1040E; color: #DADADA',
                        text: 'Cancel',
                        click: function() {
                            $( this ).dialog( 'close' );
                        }
                    }
                }
            });
        });