使用Javascript/ Jquery,如何链接具有相同类名的两个类?当单击一个时,将显示匹配的类名的内容。
<div class="menu">
<div>
<a class="about link" href=#>About</a> //this is the button to click
</div>
<div><a class="service link" href=#> Service</a> </div></div>
<aside class="overlay about"> About section</aside> //the content will display depending on which button was pressed
<aside class="overlay service"> Services </aside>发布于 2015-02-10 13:58:37
$(".link").click(function() {
var currentSelector = (typeof($(this).attr('id')) !== 'undefined' || $(this).attr('id') !== null) ? '#' + $(this).attr('id') : '.' + $(this).attr('class');
$(".overlay"+ currentSelector).show();
});显然,$(this).selector从v1.7开始就被弃用了
发布于 2015-02-10 13:59:55
$('a.about').click(function() {
$('aside.about).show();
});发布于 2015-02-10 14:00:02
$('document').ready(function(){
$('.about link').click(function(){
$('.overlay about').show();
});
});https://stackoverflow.com/questions/28425013
复制相似问题