【发布时间】:2012-05-02 00:28:03
【问题描述】:
我正在将 JQuery 模板用于我的表的数据...并且 CSS 可以识别查询模板脚本中的表行并将它们设置为我想要的样式...但是由于某种原因我不能调用 $ ().单击使用相同标识符的相同行。这是表格代码:
<script id="donorTemplate" type="text/x-jquery-tmpl">
<tr id="indexTR">
<td>${Person.LastName}, ${Person.FirstName}</td>
<td>${Address.Address1}</td>
<td>${PhoneContact.PhoneNumber}</td>
<td>${EmailContact.EmailContactx}</td>
<td>${Company.CompanyName}</td>
<td><a href="/Donation/Index?id=${Person.PersonID}">Add Donation</a></td>
<td> <a href="/Person/Edit?id=${Person.PersonID}">Edit</a> <a href="/Person/Delete?
id=${Person.PersonID}">Delete</a>
<input type="hidden" id="hiddenField" value="${Person.PersonID}"/>
</td>
</tr>
</script>
<div id="searchresults">
<table id="donor-list">
<thead>
<tr>
<th id="f" width="150">Name: </th>
<th width="180">Address: </th>
<th width="85">Phone: </th>
<th width="150">Email: </th>
<th width="100">Company: </th>
<th width="100"></th>
<th id="l" width="100"></th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
</table>
还有 JQuery....
$("#donorSearch").submit(function (event) {
event.preventDefault();
var form = $(this);
$.getJSON(form.attr("action"), form.serialize(), function (data) {
$("#tableBody #indexTR").remove();
$("#donorTemplate").tmpl(data).appendTo("#tableBody");
});
});
这都是花花公子......但这不起作用:
$("#indexTR").click(function () {
alert('test');
});
这就是我在点击 TR 时尝试做的事情:
var val = $("#hiddenField").val();
var personID = parseInt(val);
location.href = "/Person/Details?id=" + personID;
在我切换到 JQuery 模板之前一直有效。有什么建议?谢谢!
【问题讨论】:
-
等等...您是否有多个具有相同
indexTRid 的元素? -
我想......因为我每次都用不同的数据附加到该行的表中......但在我使用模型而不是 JQuery 在@foreach 中有相同的表行之前模板和点击对每一行都有效...
-
所以你得到了 invalid HTML 从 id 到 class 的变化!我认为我的回答应该对你有所帮助。
-
尝试将其指向类...这似乎也不起作用
-
这是第一阶段,结合我的答案。
标签: c# jquery asp.net-mvc asp.net-mvc-3