开发者

jquery .click href

开发者 https://www.devze.com 2023-01-31 03:51 出处:网络
anyone know why it doesn\'t work?? <script src=\"http://code.jquery.com/jquery-1.4.4.js\"></script>

anyone know why it doesn't work??

<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script>
    $('#main').click(function() {
    alert('foobar');
    doc开发者_运维问答ument.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>

pls help


Wrap the click function in a document ready function or place your code at the bottom of your page.

the #main element doesn't exist when the script is executed.

example:

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消