javascript/jquery在部分视图中不工作。
我有一个主视图,其中有一个局部视图。在我的局部视图中,我有一个表,其中显示了所执行搜索的一些结果。我想要的是,当我单击该行时,它应该提醒该行中的数据。但这并没有发生 我在网上几乎什么都试过了,但什么也找不到 局部视图:javascript/jquery在部分视图中不工作。,javascript,c#,jquery,html,Javascript,C#,Jquery,Html,我有一个主视图,其中有一个局部视图。在我的局部视图中,我有一个表,其中显示了所执行搜索的一些结果。我想要的是,当我单击该行时,它应该提醒该行中的数据。但这并没有发生 我在网上几乎什么都试过了,但什么也找不到 局部视图: @model List <string> <table class="table table-striped" id="tblGrid"> <thead id="tblHead"> <tr> &l
@model List
<string>
<table class="table table-striped" id="tblGrid">
<thead id="tblHead">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
@for (int item = 0; item < Model.Count; item = item + 2)
{
<tr>
<td style="width: 300px">
@Model[item].ToString()
</td>
@{ int temp = item;
item = item + 1;
}
<td style="width: 100px">
@Model[item].ToString()
</td>
@{
item = temp;
}
</tr>
}
</tbody>
</table>
<head>
<script type="text/javascript">
$(document).ready(function () {
$("#tblGrid tr").live(function () {
$(this).addClass('selected').siblings().removeClass('selected');
var value = $(this).find('td:first').html();
alert(value);
});
});
</script>
</head>
<body>
<input id="searchAttr" name="searchAttr" />
<button href="#myModal" id="openBtn" data-toggle="modal" class="btn btn-default">Search</button>
<div id="searchresults">
</div>
</body>
@型号列表
名称
电子邮件
@对于(int item=0;item
数据填充得很好,但没有调用javascript
main:
@model List
<string>
<table class="table table-striped" id="tblGrid">
<thead id="tblHead">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
@for (int item = 0; item < Model.Count; item = item + 2)
{
<tr>
<td style="width: 300px">
@Model[item].ToString()
</td>
@{ int temp = item;
item = item + 1;
}
<td style="width: 100px">
@Model[item].ToString()
</td>
@{
item = temp;
}
</tr>
}
</tbody>
</table>
<head>
<script type="text/javascript">
$(document).ready(function () {
$("#tblGrid tr").live(function () {
$(this).addClass('selected').siblings().removeClass('selected');
var value = $(this).find('td:first').html();
alert(value);
});
});
</script>
</head>
<body>
<input id="searchAttr" name="searchAttr" />
<button href="#myModal" id="openBtn" data-toggle="modal" class="btn btn-default">Search</button>
<div id="searchresults">
</div>
</body>
$(文档).ready(函数(){
$(“#tblGrid tr”).live(函数(){
$(this).addClass('selected').sides().removeClass('selected');
var value=$(this.find('td:first').html();
警报(值);
});
});
搜寻
如果您能提供任何帮助,我们将不胜感激。请将脚本标记放在正文而不是头部,然后再试一次您是否正在尝试使用jQuery而不将视图与之连接 将此添加到主菜单的顶部
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
浏览器控制台中是否有错误?您使用的jQuery版本是否足够旧,仍然支持.live()
?请尝试将
放在关闭
标记之前。另外,请确保在您的
之前调用jquery您好,谢谢大家的回答,但不幸的是,没有任何效果您是否在局部视图之外的任何位置使用id为=“tblGrid”的表?如果没有,则在部分视图中移动脚本标记否,仅在部分视图中移动…我也尝试过这样做,但没有成功..使用firebug检查错误,但在控制台中没有错误