如何在 MVC table 中使用 Onclick 并且仍然 jquery 来处理点击事件
How to use Onclick in a MVC table and still get jquery to process the click event too
我有一个 table 的 OnClick,效果很好。
<tr onclick="location.href = '@Url.Action("Index", new { id = item.CaseNumber, dp = item.DocumentPath, dt = item.DocumentType, sc = Model.SearchCriteria, rds = Model.ReturnDataSel })'">
但我想在它从 Url.Action 获取数据时显示一个微调器。
所以我有 jquery:
$("#res_table").click(function () {
var x = document.getElementById("spin_id");
x.style.display = "block";
如何让两者同时运行?
我看到我可以使用 .ajax 函数进行 get 调用,但我不知道如何引用 html 中的数据,即 (id,dp,dt,sc,rds)
为什么不将它们合并为一个事件?
<tr data-url="@(Url.Action("Index", new { id = item.CaseNumber, dp = item.DocumentPath, dt = item.DocumentType, sc = Model.SearchCriteria, rds = Model.ReturnDataSel }))">
然后:
$("tr").click(function () {
//Gets the URL from the data attribute
var url = $(this).data("url");
//Gets the spinner element
var x = document.getElementById("spin_id");
//Shows spinner element
x.style.display = "block";
//Redirects to URL
window.location.href = url ;
});
我有一个 table 的 OnClick,效果很好。
<tr onclick="location.href = '@Url.Action("Index", new { id = item.CaseNumber, dp = item.DocumentPath, dt = item.DocumentType, sc = Model.SearchCriteria, rds = Model.ReturnDataSel })'">
但我想在它从 Url.Action 获取数据时显示一个微调器。 所以我有 jquery:
$("#res_table").click(function () {
var x = document.getElementById("spin_id");
x.style.display = "block";
如何让两者同时运行? 我看到我可以使用 .ajax 函数进行 get 调用,但我不知道如何引用 html 中的数据,即 (id,dp,dt,sc,rds)
为什么不将它们合并为一个事件?
<tr data-url="@(Url.Action("Index", new { id = item.CaseNumber, dp = item.DocumentPath, dt = item.DocumentType, sc = Model.SearchCriteria, rds = Model.ReturnDataSel }))">
然后:
$("tr").click(function () {
//Gets the URL from the data attribute
var url = $(this).data("url");
//Gets the spinner element
var x = document.getElementById("spin_id");
//Shows spinner element
x.style.display = "block";
//Redirects to URL
window.location.href = url ;
});