对话框关闭按钮,是否有默认名称或样式等工作?

时间:2013-08-23 14:01:12

标签: jquery jquery-ui

我正在使用UI对话框,是否有样式或名称或我可以给取消按钮的任何内容,以使其默认关闭对话框?这是我当前的按钮

        <input type="button" value="Cancel" name="close" id="btncancel" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" />

由于

编辑:这是我当前的Dialog代码和尝试事件

$(".editDialog").on("click", function (e) {
        var url = $(this).attr('href');
        $("#dialog-edit").dialog({
            title: 'Edit',
            autoOpen: false,
            resizable: true,
            autoResize:true,
            minHeight: 'auto',
            width: width,
            modal: true,
            draggable: true,
            open: function (event, ui) {
                //Show the loading div on open.
                $("#dvLoading").show();
                //adding a callback function wich will be launched after the loading
                $(this).load(url,function(response, status, xhr) {
                    if (status == "error") {
                        var msg = "Sorry but there was an error: ";
                        $(this).html(msg + xhr.status + " " + xhr.statusText);
                    } else $("#dvLoading").hide();
                });
            },
            close: function (event, ui) {
                $(this).dialog('close');
            },
            buttons: {
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

        $("#dialog-edit").dialog('open');
        return false;
    });

2 个答案:

答案 0 :(得分:0)

请参阅dialog box example

<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Dialog - Modal confirmation</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:140,
      modal: true,
      buttons: { // here you can make your button remove ok button then only cancel button come
        "Delete all items": function() {
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });
  </script>
</head>
<body>

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

<p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p>


</body>
</html>

答案 1 :(得分:0)

我只是添加了另一个功能,工作正常

function CancelDialog() {
    $("#dialog-edit").dialog().dialog('close');
}