jquery 使用a标签导航栏跳转页面,动态添加高亮

it2022-05-05  106

众所周知,使用a标签跳转之后,会刷新一次,继而这个添加的样式就会消失。那么怎么解决这一问题呢?

<script> $(function () { $('.bar a').each(function () { if ($($(this))[0].href == String(window.location)) $(this).addClass('active').attr('href', 'javascript:void(0);'); }); }); </script>

这样就好了

转载于:https://www.cnblogs.com/mica/p/11162480.html


最新回复(0)