我想突出显示我的元素并添加一个jQuery链接。jQuery代码不适用于MVC3网站
我的代码:
@model IEnumerable<Mvc3Demo.Products>
@{
ViewBag.Title = "List";
}
<h2>List</h2>
<script type="text/javascript" src="../../Scripts/jquery-1.5.1.min.js" />
<script type="text/javascript">
$(document).ready(function() {
$('#productList li').hover(
function() {
$(this).css({ 'background': 'green', 'cursor': 'pointer' });
},
function() {
$(this).css('background', '');
}
).click(function() {
window.location = 'Product/Edit/' + $(this).attr('productid');
});
});
</script>
<ul id="productList">
@foreach (Mvc3Demo.Products p in Model)
{
<li productid="@p.ProductsID">
@p.Name
<[email protected]("Bearbeiten", "Edit", "Product", p, null)-->
</li>
}
</ul>
布局页:
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
</head>
<body>
@RenderBody()
</body>
</html>
jQuery的会被发现,这样不可能是错误(我用萤火虫校对吧)
错误:
在Firebug中没有错误,没有高亮和没有链接
请帮
尝试在Firebug的控制台写作'$( '#productList的礼')'。它是否返回任何元素? – lalibi
返回:[li,li] – test123123
现在它突然工作 – test123123