关于超链接Javascript对象的问题

时间:2010-10-12 22:24:02

标签: javascript

我可以在5秒后显示按钮。我希望能够点击该按钮并转到其他网站(例如google.com)。请帮忙吗?

<style type="text/css">

#buy_button_image { display: none; }

</style>

<script type="text/javascript">

window.onload = function()
{
var img = document.getElementById("buy_button_image");
var _t = function() {
    img.style.display = "block";
};
window.setTimeout(_t, 5000);
window.clearTimeout(_t);
};
</script>

</head>

<body>
<img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png">
</body>
</html>

3 个答案:

答案 0 :(得分:1)

改变这个:

<img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png">

要:

<div id="buy_button_image"><a href="http://google.com/"><img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png"></a></div>

答案 1 :(得分:1)

使用a标记:

请注意,您的clearTimeout不执行任何操作。请查看 setTimeout() clearTimeout() 引用。

<html>
<head>
<style type="text/css">    
    #buy_button_image { display: none; }
</style>

<script type="text/javascript">
window.onload = function()
{
    var img = document.getElementById("buy_button_image");
    var _t = function() {
        img.style.display = "block";
    };
    window.setTimeout(_t, 5000);
};
</script>

</head>

<body>
    <a href="http://www.pumaskills.com" id="buy_button_image">
        <img style="border: medium none ;" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png">
    </a>
</body>
</html>​​​​​​​​​​​​​​

Try it out with this jsFiddle

答案 2 :(得分:0)

锚标记?

<style type="text/css">

#buy_button_image { display: none; }

</style>

<script type="text/javascript">

window.onload = function()
{
var img = document.getElementById("buy_button_image");
var _t = function() {
    img.style.display = "block";
};
window.setTimeout(_t, 5000);
window.clearTimeout(_t);
};
</script>

</head>

<body>
<a href="http://www.stackoverflow.com"><img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png"></a>
</body>
</html>