[英]javascript/jquery not working in the partial view.
我有一个主要观点,其中有一个局部观点。 在我的局部视图中,我有一个表,其中显示了一些搜索结果。 我想要的是,当我单击该行时,它应该警告该行中的数据。 但这没有发生。
我几乎尝试了互联网上的所有内容,但找不到任何内容。
部分视图:
@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>
数据可以很好地填充,但是不调用javascript。
主要:
<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>
提供的任何帮助将不胜感激。
将您的脚本标签放在身体而不是头部,然后尝试
您是否在尝试使用jQuery而不将其与视图连接?
添加到您的主要内容的顶部
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.