我在 jsfiddle 中测试了下面的脚本,它工作正常,有人可以指导我如何修复它吗?这是我需要它工作的 url,右上角的向导样式菜单应在单击时将每个元素设置为事件状态,然后在单击另一个菜单项时将其删除:http://morxmedia.com/clients/temp/45p/index_vertical.html
这是我为此使用的代码:
<script type="text/javascript">
$('.wizard-steps div').click(function(e) {
e.preventDefault();
$('a').removeClass('active');
$(this).addClass('active');
});
</script>
最佳答案
当您应该像这样将它们绑定(bind)到 a
元素时,您正在将点击事件绑定(bind)到 div
元素
$(document).ready(function(){
$('.wizard-steps > div > a').click(function(e) {
e.preventDefault();
$('a').removeClass('active');
$(this).addClass('active');
});
});
关于javascript - 将类设置为事件并在选择另一个菜单项时将其删除错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11222386/