简体   繁体   English

如何使用javascript中的按钮加载HTML页面

[英]How load HTML Pages, using button in javascript

I want to make button to load a html page using javascript. 我想让按钮使用javascript加载html页面。 (Like Ajax Codes I don't want the page redirection).... but the code can't load html page & i want it to fill the page view. (就像Ajax代码一样,我不希望页面重定向)....但是代码无法加载html页面和我希望它填充页面视图。

so here is the code: 所以这是代码:

<!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<button type="button"
onclick="document.getElementById("demo").innerHTML='<object type="type/html" data="register.html" >
submit</button>
<p id="demo"></p>

</body>
</html>

You have to escape the double quotes. 您必须转义双引号。 Example: 例:

<button type="button"
   onclick=" document.getElementById(\"demo\").innerHTML=
      '<object type=\"type/html\" data=\"http://www.target.com/register.html\">' ">
submit</button>

try like this: 尝试这样:

    <!DOCTYPE html>
    <html>
    <style>
      #demo{
      width:700px !important;
      height:600px !important;

      }


  </style>
    <script>

    function loadPage(){
        document.getElementById("demo").innerHTML="<object type='type/html' data='register.html' >";

    }


      </script>
    <body>

    <h1>My First JavaScript</h1>

    <button type="button"
    onclick="loadPage();" >
    submit</button>
    <p id="demo"></p>

    </body>
    </html>

note: here register.html and this file should be in same folder or give relative path. 注意:此处的register.html和此文件应位于同一文件夹中或提供相对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM