1

我在表格中有以下内容,对每一行重复:

<a <?php echo 'id="'.$id.'"'; ?> class="custom-dialog-btn btn btn-small">
   <i class="icon-trash"></i>
</a>

每行的位置id不同,因为它取自数据库中的主键表。

然后,我使用了以下 jQuery 代码:

$(".custom-dialog-btn").bind("click", function (event) {
                $("#mws-jui-dialog").dialog("option", {
                    modal: false
                }).dialog("open");
                event.preventDefault();
            });

      $("#mws-jui-dialog").dialog({
        autoOpen: false,
        title: "Alert",
        modal: true,
        width: "640",
        buttons: [{
            text: "NO",
        id: "cancel_button",
            click: function () {
                $(this).dialog("close");
            }
        },
     {
        text: "OK",
        id: "confirm_button",
            click: function () {
                myremovefuntion(id); // I need the id
        }}
    ]
    });

指的是对话框:

<div id="mws-jui-dialog">
    <div class="mws-dialog-inner">
    <h2>Are you sure you want to delete?</h2>
    </div>
</div>

如何将 id 传递给模态?

4

3 回答 3

3

You can append a data attribute to your dialog div as follows;

$('a').click(function (e) {
    e.preventDefault();
    $("#your_dialog").data('mycustomdata', $(this).prop('id')).dialog('open');
});

And retreive it like this

    $("#your_dialog").dialog({
        autoOpen: false,
        resizable: false,
        height:200,
        modal: true,
        buttons: {
            Cancel: function() {
                $(this).dialog('close');
            },
            'Delete': function() {
                $(this).dialog('close');
                var mydata = $(this).data('mycustomdata'); // = gives you the id of anchor element
// some delete logic
            }
        }
    });
于 2013-07-06T15:06:43.900 回答
0

Use the following code to get the id:

var id = $(this).prop("id");

And you will get the id of that which element you have clicked.

于 2013-07-06T15:06:39.883 回答
0

虽然 Emin 的答案确实有效,但我想知道这个 fabuolus jQuery UI 库是否可能具有类似于 JavaScript 的本机confirm()方法的对话风格?或者也许可以传入回调函数?这将消除包含业务逻辑的对话代码的需要。

于 2013-07-06T15:14:55.837 回答