2013-04-10 66 views
0

我正在嘗試創建一個hrefs到另一個頁面的按鈕。這裏的HTML:<button>不起作用

<div class="new_user"> 
<button id="buton_user_nou">Creaza User 
</button> 
</div> 

和jQuery:

$('#buton_user_nou').click(function(){ 
location.href='/register.htm' 
}) 

按鈕是完全無效的,在所有瀏覽器。它甚至沒有突出當懸停... 任何指針?

+1

添加加載前jQuery和文檔準備功能! – adeneo 2013-04-10 19:25:52

+1

位於HTML文檔中的JavaScript在哪裏?確保你遵循了jQuery教程:http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery。在那裏解釋你需要知道的一切。 – 2013-04-10 19:33:00

回答

0

您缺少zemi冒號,也建議將事件註冊碼放在文檔中。這將確保添加事件時存在dom元素。

$(document).ready(function() { 
    $("#buton_user_nou").click(function() { 
     location.href='/register.htm'; 
    }); 
}); 
+0

非常感謝您的回覆,我糾正了jQuery。 – Alex 2013-04-10 19:41:32

+0

但我仍然有主要問題,該按鈕是完全無效的,沒有任何反應,當我點擊它,它甚至沒有突出顯示.. – Alex 2013-04-10 19:42:50

0

我不知道你在哪裏放置你的腳本,但問題可能是,DOM完成加載之前腳本被執行,所以沒有按鈕的jQuery找到。

由於adeneo指出的,只是包裝文檔ready函數中的代碼:

$(document).ready(function() { 
    $('#buton_user_nou').click(function() { 
    location.href='/register.htm' 
    }); 
}); 
0

嘗試..

$(window).load(function(){ 
    $("#buton_user_nou").click(function() { 
    location.href='/register.htm'; 
    }); 
}); 

這樣一來就會文檔:)