且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JQuery的 - 需要显示在页面上的任何锚链接点击模态对话框

更新时间:2023-12-02 23:53:40

所以,如果你做了这样的事情:

So, if you did something like this:

$('a').click(function(e) {
   alert('anchor clicked');
}); 

你会得到警告,每点击主播在页面上 - 不是你想要什么可能性。如果您分配这些锚的一类,那么你可以这样做:

you'd get that alert for every anchor clicked on the page - not likely what you want. If you assigned those anchors a class, then you could do this:

$('a.myclass').click(function(e) {
   alert('anchor clicked');
}); 

,然后你会得到的只是这是该类的锚警报。对于模态对话框的一部分,你可以只替换了,我已经得到了警报,基本上是在页面上创建一个隐藏的div作为模态对话框使用。我做了这样的事情,它看上去是这样的:

and then you'd get the alert for just the anchors which were of that class. For the modal dialog part, you could just substitute that where I've got the alert, essentially creating a hidden div on the page to use as the modal dialog. I did something like this and it looked something like:

$('a.myclass).click(function () {
   // add the div or reuse it
   var modaldialog = ($('#ModalDialog').length > 0)
     ? $('#ModalDialog')
     : $('<div id="ModalDialog" style="display:hidden"></div>').appendTo('body');
   load up data via ajax call
   $.get('@Url.Action("MyAction", "MyController")', {},
      function (responseText, textStatus, XMLHttpRequest) {
         modaldialog.html(responseText);
         modaldialog.dialog({
            modal: true,
            width: 500,
            title: 'My Modal Dialog',
         });
      }
   );
});

无论如何,这是一个开始。您可以添加按钮,对话框以及和有那些做基于任何特定需求的东西。

Anyway, that's a start. You can add buttons to the dialog as well and have those do things based on whatever your particular needs are.