点击链接加粗链接
问题描述:
我想要使用jquery在点击链接时将我的超链接改为粗体,并在点击另一个链接时将其切换回正常状态。点击链接加粗链接
这些都是我想点击
<div id="secondlevel">
<ul>
<li><span><a href="NewReleases.aspx?catalogueCode=cat1">New Releases</a></span></li>
<li><span><a href="BestSellers.aspx">Best Sellers</a></span></li>
</ul>
链接这是我的查询,我觉得应该工作,但没有。
也许可以提供建议。
$(document).ready(function() {
$("li").on("click", function() {
$(this).siblings("li").css("fontWeight", "normal");
$(this).css("fontWeight", "bold");
window.alert("The link was clicked");
});
});
答
使用e.preventDefault()
防止默认动作:
$("li").on("click", function (e) {
e.preventDefault();
$(this).siblings("li").css("fontWeight", "normal");
$(this).css("fontWeight", "bold");
window.alert("The link was clicked");
});
答
试试这个:
$(document).ready(function() {
$("li").on("click", function() {
$(this).siblings("li").find('a').css("font-weight", "normal");
$(this).find('a').css("font-weight", "bold");
});
});
你是什么意思是 “应该工作,但不” 吗?你期望会发生什么,而发生什么呢? – yoozer8 2013-04-26 12:36:41
为什么你不使用CSS?,顺便说一句,你的页面刷新,对吧?那种情况下,这就是为什么你的jQ不起作用。 – 2013-04-26 12:36:58
@roXon,他通过jQuery改变了CSS。 – smerny 2013-04-26 12:38:09