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

时间:2014-06-25 20:26:06

标签: jquery asp.net-mvc

查看:

 <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,filename,fileextension发送到我的对话框?

查看:

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

我不想使用viewbag ..

谢谢!

1 个答案:

答案 0 :(得分:0)

你可以这样做:

<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();
});