1

所发生的只是它闪烁了一秒钟,我想让我的按钮可见,但它不打印 hello world 并且它不会停留在那里只是闪烁。

<html>

<head>
  <script src="Document.js"></script>
  <script type="text/javascript">
    function All() {
      var name = document.getElementById("search");
      visible()
    }

    function visible() {
      document.getElementById("back").style.visibility = "visible";
      David()
    }

    function David() {
      if (name === "David") {
        Document.write(
          "Hello World"
        );
      }
    }
  </script>
</head>

<body onload=" invisible()">
  <center>
    <h2>Enter A Last Name</h2>
    <form>
      <input style="width: 300px;position: relative;top: 100px;" id="search" type="textbox" name="search">
      <input style="position: relative;top: 100px;" type="submit" value="search" name="button" onClick="All()">
      <input style="position: relative; right: 900px;" id="back" type="submit" value="Back" name="button" onClick="">
    </form>
  </center>
</body>

</html>

此外,这onload=" invisible()"只是调用一个函数,<script src="Document.js"></script>但我没有任何问题,它所做的只是在页面加载时使按钮不可见,但无论如何这里是它的代码。

function invisible()
{
    document.getElementById("back").style.visibility="hidden";
}
4

2 回答 2

0

You are using a form submit for it and the default event for form submit is to go to the action specified on the form. If there is no action on the form, it just refreshes the page. If you want to keep the form submit, you have to stop the default event with return false;

function All (){
var name = document.getElementById("search");
visible();
return false;
}

That should fix your problem.

You could also use a "button" tag or just an "a" tag.

于 2013-11-09T16:56:00.697 回答
0

将提交更改为按钮使我的对象“返回”可见,但它没有删除搜索栏和搜索按钮,也没有打印 hello world 但感谢您的帮助

于 2013-11-09T17:04:46.160 回答