【发布时间】:2015-05-25 08:50:11
【问题描述】:
@Html.ActionLink 标签有一个小问题。我想在点击它时更改背景。但它不起作用。
<ul>
<li>@Html.ActionLink("View Profile", "Profile", "User", null, new { id = "profile" })</li>
</ul>
以及 jQuery 代码:
$("#profile").click(function () {
document.getElementById("profile").style.background = "linear-gradient(#00ff66, #00ff99, #00ff66)";
});
但我在 w3schools 上试过,它已经奏效了:
<!DOCTYPE html>
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<a id="profile" href"">View profile</a>
<script>
$("#profile").click(function() {
document.getElementById("profile").style.background = "linear-gradient(#00ff66, #00ff99, #00ff66)";
});
</script>
</body>
</html>
你能帮帮我吗?
p/s:这是我的子问题:
你能告诉我有什么区别吗:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<a id="profile" href"">View profile</a>
<script>
$("#profile").click(function() {
document.getElementById("profile").style.background = "linear-gradient(#00ff66, #00ff99, #00ff66)";
});
</script>
和
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$("#profile").click(function() {
document.getElementById("profile").style.background = "linear-gradient(#00ff66, #00ff99, #00ff66)";
});
</script>
<a id="profile" href"">View profile</a>
如果我将<a id="profile" href"">View profile</a> 行的位置更改为末尾,代码将无法运行。
为什么?
【问题讨论】:
标签: javascript jquery html.actionlink asp.net-mvc-5.2