如何为特定链接调用javascript?
JavaScript应用于所有A链接,但它只在我单击此特定A链接(#tornado,#bar->ul->li->A链接)时起作用,我如何在js中提及此A链接 这个js不起作用如何为特定链接调用javascript?,javascript,jquery,Javascript,Jquery,JavaScript应用于所有A链接,但它只在我单击此特定A链接(#tornado,#bar->ul->li->A链接)时起作用,我如何在js中提及此A链接 这个js不起作用 <html> <head> <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script> <style type="text/css">
<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
<style type="text/css">
.active{
background-color:#a00;
color:#fff;
}
</style>
</head>
<body>
<div id="viran">
<div id="mob" class="hide_yellow2">
<div id="tornado_bar">
<a href="#" id="menu-icon">visit</a>
<ul>
<li><a title="index.html" href="#786">Home</a></li>
<li><a title="#about" href="#787">About</a></li>
<li><a title="#minnummannai" href="#788" >Minnum Mannai</a></li>
<li><a title="#inassembly" href="#789">In Assembly</a></li>
</ul>
</div>
</div>
<ul>
<li><a title="#minnummannai" href="#788" >Minnum Mannai</a></li>
<li><a title="#inassembly" href="#789">In Assembly</a></li>
</ul>
</div>
<script>
$('a').click(function (e) {
e.preventDefault();
$('a').removeClass('active');
$(this).addClass('active');
});
</script>
</body>
</html>
.主动{
背景色:#a00;
颜色:#fff;
}
$('a')。单击(函数(e){
e、 预防默认值();
$('a').removeClass('active');
$(this.addClass('active');
});
您正在寻找的基本CSS选择器是一个简单的空格:#tornado_bar a
:
$('#tornado_bar a').click(function (e) {
e.preventDefault();
$('#tornado_bar a').removeClass('active');
$(this).addClass('active');
});
您正在寻找的基本CSS选择器是一个简单的空格:
#tornado\u bar a
:
$('#tornado_bar a').click(function (e) {
e.preventDefault();
$('#tornado_bar a').removeClass('active');
$(this).addClass('active');
});
您在
#tornado
中有五个链接。你想看哪一个?#tornado_bar->ul->li->a links@David Thomasy你在#tornado
中有五个链接。你想看哪一个?#tornado_bar->ul->li->a链接@David Thomas