2013-04-10 65 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'; 
    }); 
}); 

这样一来就会文档:)