代码可以在以下位置查看:
http://fxv4.com/js/java.html
(来源:查看源:http://fxv4.com/js/java.html)
问题是里面的代码不会改变url。问题不大,但是如果您删除标签,该功能将不起作用。倒计时也不行。我只想让 js btn 中的 url 像普通的提交/js btn 一样隐身。
我很感激任何帮助,谢谢!
代码可以在以下位置查看:
http://fxv4.com/js/java.html
(来源:查看源:http://fxv4.com/js/java.html)
问题是里面的代码不会改变url。问题不大,但是如果您删除标签,该功能将不起作用。倒计时也不行。我只想让 js btn 中的 url 像普通的提交/js btn 一样隐身。
我很感激任何帮助,谢谢!
您必须重新排列代码并了解 HTML/JS 的基础知识。请记住以下几点:
<body>
放在head
.例子:
<html>
<head>
<script type="text/javascript">
// (2) Run JavaScript after DOM document has loaded.
window.onload = function() {
var message = document.getElementById('message');
var button = document.getElementById('button');
var counter = 5;
var interval = setInterval(function() {
if (counter === 0) {
button.style.display = 'block';
message.style.display = 'none';
clearInterval(interval);
}
message.innerHTML = 'You can view the url in ' + (counter--) + ' seconds.';
}, 1000);
button.onclick = function() {
window.location = 'http://google.ch/';
};
};
</script>
<style type="text/css">
button { display:none; }
</style>
</head>
<body>
<!-- (1) HTML element live inside the body. -->
<span id="message">...</span>
<button id="button">Visit Page Now</button>
</body>
</html>
您当前的代码:
<a href="http://fxv4.com/js/java.html" id="download" class="button">
<button onclick="window.location='http://URL undefined';">Visit Page Now</button>
</a>
添加到按钮onclick返回语句false,所以点击事件不会被发送到父元素:
<a href="http://fxv4.com/js/java.html" id="download" class="button">
<button onclick="window.location='http://URL undefined';return false">Visit Page Now</button>
</a>