-1

代码可以在以下位置查看:

                 http://fxv4.com/js/java.html

(来源:查看源:http://fxv4.com/js/java.html)

问题是里面的代码不会改变url。问题不大,但是如果您删除标签,该功能将不起作用。倒计时也不行。我只想让 js btn 中的 url 像普通的提交/js btn 一样隐身。

我很感激任何帮助,谢谢!

4

2 回答 2

0

您必须重新排列代码并了解 HTML/JS 的基础知识。请记住以下几点:

  1. 您应该只将 HTML 元素<body>放在head.
  2. 更改 HTML 元素的 JavaScript 代码必须在 DOM 文档加载后执行。

例子:

<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>
于 2012-11-25T16:20:46.310 回答
0

您当前的代码:

<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>
于 2012-11-25T16:02:46.227 回答