Jquery 按钮ok,但href链接不';t火

Jquery 按钮ok,但href链接不';t火,jquery,Jquery,我有JQuery代码: $("#step1Skip").on("click", function(event){ $('#chooseTheme, #addImages, #addVideo, #finalStep').hide(); $('#addLogo').show(); }); 如果我使用按钮,例如 <button type="button" id="step1Skip">Skip this step >></button> 跳过此

我有JQuery代码:

$("#step1Skip").on("click", function(event){
    $('#chooseTheme, #addImages, #addVideo, #finalStep').hide();
    $('#addLogo').show();
});
如果我使用按钮,例如

<button type="button" id="step1Skip">Skip this step >></button>
跳过此步骤>>
这个很好用。但是,如果我用一个简单的链接尝试相同的方法:

<a href="#" id="step1Skip">Skip this step</a>

它什么也不做,根本不起作用。为什么呢


我不会同时尝试它们,因此这不是ID问题。

您的浏览器正在尝试跟踪链接。试用


这将防止链接的默认操作发生。

由于它是一个链接,因此链接正在执行其默认操作。您需要阻止它这样做,并使用
preventDefault()

另一个注意事项-这仅适用于

有助于理解默认操作如何与链接一起工作

$("#step1Skip").on("click", function(event){
    event.preventDefault();
    $('#chooseTheme, #addImages, #addVideo, #finalStep').hide();
    $('#addLogo').show();
});
$("#step1Skip").on("click", function(event){
    event.preventDefault();
    $('#chooseTheme, #addImages, #addVideo, #finalStep').hide();
    $('#addLogo').show();
});