使用JQuery对话框http://jqueryui.com/dialog/#modal-confirmation
每当页面加载时,都会出现该对话框,我只希望在单击“删除发票”时显示它。

我试过了:<input id="RemoveInvoice" type="button" value="Remove Invoice" onclick="ConfirmDeleteInvoice()" />

然后将实际的JS放入ConfirmDeleteInvoice函数中:

  function ConfirmDeleteInvoice() {
      //  $(function () { //removed this line and added the above line
        $("#dialog-confirm").dialog({
            resizable: false,
            height: 140,
            modal: true,
            buttons: {
                "Are you sure you want to delete this invoice": function () {
                    $(this).dialog("close");
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            }
        });
    });
    }


错误:JavaScript运行时错误:“ ConfirmDeleteInvoice”未定义

抱歉仍然是JS的初学者,请耐心等待。
谢谢

最佳答案

在最后一个括号之前,您还有一个额外的结尾});,将其取出即可使用。

另外,在我的小提琴中,您会看到我在jQuery中添加了click事件,因为HTML内的onclick被认为是不良做法。我这样做是通过添加:

$("#RemoveInvoice").click(ConfirmDeleteInvoice);


看到这里:http://jsfiddle.net/P4VHw/

关于javascript - jQuery对话框-仅在单击按钮时加载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15662772/

10-13 01:45
查看更多