添加了javascript,现在链接don'不起作用

Added javascript and now links don't work

本文关键字:don 不起作用 链接 javascript 添加      更新时间:2023-09-26

我添加了javascript来检测何时点击链接,这可以正常工作,但现在链接不起作用(即,它们不会将用户带到链接页面)。

HTML:

<div class="designflow" style="padding-left:50px;padding-right:0px;padding-top:0px;padding-bottom:15px;margin-top:0px;float:left; font-size:18px; color: gray; height:150px; width:150px;margin-left:auto;margin-right:auto;display:inline-block;"> 
<a href = "/manufacturing/" class = "designflow" id = "manufacturing">
<img src="{{STATIC_URL}}pinax/images/manufacturing.png" width = "150px" style=margin-bottom:0px;" alt=""><br>
<p style="position:absolute;bottom:25px;padding-left: 0px; padding-right:0px; width:150px;text-align:center;">Manufacturing</p></a>
</div>

JQUERY:

jQuery( 'div.designflow a' )
    .click(function() {
        do_the_click( this.id );
        return false;
    });
function do_the_click( designstage )
{
    alert(designstage);
}

点击处理程序由于返回错误而禁用它们

当您从事件处理程序返回false时,您会告诉运行时停止处理它。这还包括停止默认操作。在这种情况下,要阻止链接成为链接。

如果删除"return false"行。然后链接将像链接通常再次那样工作

jQuery( 'div.designflow a' )
    .click(function() {
        do_the_click( this.id );
    });

但是,根据方法的名称,您可能确实希望返回false,然后在事件处理程序中处理重新定位。

在JavaScript中,你可以导航到一个新的url,如下所示:

window.location = newUrl;

因为在函数中编写return false,所以如果要编写它,必须将页面重定向到javascript 中的链接地址

示例

jQuery( 'div.designflow a' )
    .click(function() {
        do_the_click( this.id );
        window.location="/manufacturing";
return;
    });
function do_the_click( designstage )
{
    alert(designstage};
}
</script>

通过在事件函数中返回false,您显式地抑制了事件的正常行为。您应该返回true,以便在执行代码后浏览器正常处理事件。

i将function更改为返回真实

jQuery( 'div.designflow a' )
    .click(function() {
       do_the_click( this.id );
       return true;
    });