jQuery Dialog将参数从脚本传递到对话框div



视图:

 <img src="~/Content/images/delete.png" onclick="abc" />

脚本:

function abc(blobname, filename, fileextension) {
        $('#my-dialog').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            modal: true,
            buttons: {
                "Ok": function () {
    codeblablabla
                        $(this).dialog("close");
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

是否可以将参数blobname、文件名、文件扩展名发送到我的对话框?

视图:

<div id="my-dialog"><div>Are you sure you want to delete file: filename+blobname</div></div>

我不想使用viewbag。。

谢谢!

您可以这样做:

<img 
  src="~/Content/images/delete.png"
  data-dialog="Are you sure you want to do this?" 
  data-blobname="blah"
/>

然后这样引用它:

$("[data-dialog]").click(function(){
  var msg = $(this).data("dialog");
  var blobname = $(this).data("blobname");
  // now build your dialog, using the vars created above
  $('<div />').html(msg).dialog();
});

最新更新