Javascript jQuery-单击列表时替换div类
有人能帮我写一个jQuery脚本,在单击链接时将一个div类替换为另一个类吗。 我有一个地址列表,我希望在单击地址时更改地图图像。由于css的结构和图像上的渐变,简单地更改背景图像url是没有帮助的。 我为每个地址创建了4个类,每个类都有每个地址的背景图像 我简化了我的代码,以便更容易编写脚本。这就是我建造的: 图像包装器:Javascript jQuery-单击列表时替换div类,javascript,jquery,html,image,replace,Javascript,Jquery,Html,Image,Replace,有人能帮我写一个jQuery脚本,在单击链接时将一个div类替换为另一个类吗。 我有一个地址列表,我希望在单击地址时更改地图图像。由于css的结构和图像上的渐变,简单地更改背景图像url是没有帮助的。 我为每个地址创建了4个类,每个类都有每个地址的背景图像 我简化了我的代码,以便更容易编写脚本。这就是我建造的: 图像包装器: <div class="map-wrapper map1"> </div> 我想编写一个jQuery脚本,在单击相关地址链接时将类“map1”更改
<div class="map-wrapper map1">
</div>
我想编写一个jQuery脚本,在单击相关地址链接时将类“map1”更改为“map2、3或4”。这将依次更改背景图像!:)
那么,谁能帮帮我吗!我是一个javascript和jQuery新手,知道的不多
$('ul li a').on('click', function(e) {
e.preventDefault();
var cl = $(this).attr('href').replace('#','');
$('.map-wrapper').removeClass().addClass('map-wrapper '+cl);
});
你需要像
$('.map-wrapper').removeClass().addClass('map-wrapper '+$(this).attr('id'));
在函数末尾添加以下内容:
$(".map-wrapper").removeClass("map1 map2 map3 map4").addClass(id);
什么是地图?
?@LightStyle-我自己刚刚注意到了,我想输入速度很快,谢谢!有时也会发生,别担心:D+1!
$('.map-wrapper').removeClass().addClass('map-wrapper '+$(this).attr('id'));
$(".map-wrapper").removeClass("map1 map2 map3 map4").addClass(id);