jquery.click href
有人知道为什么它不起作用吗jquery.click href,jquery,href,Jquery,Href,有人知道为什么它不起作用吗 <script src="http://code.jquery.com/jquery-1.4.4.js"></script> <script> $('#main').click(function() { alert('foobar'); document.location.href='02.html'; }); </script> <style type="text/css"&
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script>
$('#main').click(function() {
alert('foobar');
document.location.href='02.html';
});
</script>
<style type="text/css">
body {margin:0px; background:#f2f2f2;}
#main {background:url(01.jpg) top center no-repeat; height:1745px; width:100%; text- align:center; overflow-x:hidden; cursor:pointer; cursor:hand;}
</style>
</head>
<body>
<div id="main"></div>
</body>
$('#main')。单击(函数(){
警报(“foobar”);
document.location.href='02.html';
});
正文{边距:0px;背景:#f2f2;}
#main{background:url(01.jpg)top-center不重复;高度:1745px;宽度:100%;文本-对齐:居中;溢出-x:隐藏;光标:指针;光标:手;}
请帮助将单击功能包装在文档就绪功能中,或将代码放在页面底部 执行脚本时#main元素不存在 例如:
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script>
$(document).ready(function() {
$('#main').click(function() {
document.location.href='02.html';
});
});
</script>
$(文档).ready(函数(){
$('#main')。单击(函数(){
document.location.href='02.html';
});
});
这是我不喜欢jQuery的一点——当您不选择任何对象时,它会返回一个有效但为空的对象。我知道这个功能很有用,但对初学者来说也很粗糙,而且很难调试。