2014-06-25 43 views
0

查看:jQuery的对话通过从脚本参数对话框的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,文件名,fileextension我的对话?

查看:

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

我不想使用viewbag ..

谢谢!

回答

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

嘿感谢,但我怎么使用,在我看来,DIV对话变量?我对js不太了解?我设法在onclick事件中传递参数,所以我alrdy知道如何将params传递给脚本 – Reft

+0

@reft请参阅我的编辑。 – rybo111

+0

对不起,但它没有为我工作。相反,我只是增加了: $(“#my-dialog”)。text(“text here with variables”); 打开对话框之前 谢谢! – Reft