簡體   English   中英

添加了JavaScript,現在鏈接不起作用

[英]Added javascript and now links don't work

我添加了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禁用了它們

從事件處理程序返回false時,您告訴運行時停止對其進行處理。 這還包括停止默認操作。 在這種情況下,阻止鏈接成為鏈接。

如果您刪除“返回假”行。 然后,該鏈接將像正常情況一樣再次起作用

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

但是,從方法的名稱中考慮,您可能確實想返回false,然后在事件處理程序中處理重定位。

在JavaScript中,您可以這樣導航到新的網址:

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,以便在執行代碼后瀏覽器可以正常處理該事件。

我將function更改為返回true

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM