JQuery - 需要在页面上的任何锚链接单击上显示模式对话框
在我的剃刀视图中,我有带有锚的桌子。下面显示的单元格之一:
@foreach (MillitarySlot slot in item.SundaySlots)
{
<a style="color:@slot.Color" title="@slot.ToolTip" href="@slot.HRef">@slot.SlotText</a><br />
}
如果用户单击任何锚点,那么我需要显示模式对话框。我怎样才能实现这个目标?
In my razor view, I have got table with the anchors. One of the cell shown below:
@foreach (MillitarySlot slot in item.SundaySlots)
{
<a style="color:@slot.Color" title="@slot.ToolTip" href="@slot.HRef">@slot.SlotText</a><br />
}
If user clicks any of the anchor then I need to show modal dialog. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以,如果你做了这样的事情:
你会收到页面上点击的每个锚点的警报 - 这不太可能是你想要的。如果您为这些锚点分配了一个类,那么您可以执行以下操作:
然后您将收到属于该类的锚点的警报。对于模式对话框部分,您可以替换我收到警报的位置,本质上是在页面上创建一个隐藏的 div 来用作模式对话框。我做了类似的事情,看起来像:
无论如何,这是一个开始。您也可以向对话框添加按钮,并让这些按钮根据您的特定需求执行操作。
So, if you did something like this:
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:
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:
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.
您可以给该锚点一个 id(用于 jQuery 性能)并绑定一个单击事件,该事件通过 Ajax 获取模式对话框,然后返回 false(如果用户禁用了 JavaScript,他应该继续,否则对话框将出现)
You could give that anchor an id ( for jQuery performance ) and bind a click event that gets the modal dialog through Ajax for instance and after that return false ( if the user has JavaScript disabled he should proceed else the dialog shall appear )