如何在点击链接时包含html文件

How to include html file on click link

本文关键字:包含 html 文件 链接      更新时间:2023-09-26

嗨,我想在链接上包含一个文件,点击这里,我做了以下代码,但它在我的html页面中不起作用

这是下面给出的我的代码

    $("#reset").click(function() {
          $(function() {
              $("#RightPaneContainerDiv").html('<iframe src="open.php"></iframe>');
          });
    });
     <a href="#" id="reset"></a>

我在以下代码中的错误

如何实现我的输出

在将链接包含在HTML中之前,您要将JavaScript处理程序绑定到链接。

点击事件触发后,您将延迟反应,直到DOM准备好——点击链接时DOM不太可能还没有准备好。

交换您的两个事件处理程序。

等待DOM准备就绪。然后绑定事件处理程序。

$(function() {
    $("#reset").click(function() {
        $("#RightPaneContainerDiv").html('<iframe src="open.php"></iframe>');
    });
});

我看到的第一件事是

$(function(){

当你执行.click函数时,不要调用ready函数,所以你的代码应该是这样的:

     $("#reset").click(function() {
              $("#RightPaneContainerDiv").html('<iframe src="open.php"></iframe>');
    });
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
  function resetclick() {
    $("#yourDiv").html('<iframe src="open.php"></iframe>');
  }
</script>
 <a href="#" onclick="resetclick()" id="reset">fafa</a>
<div id="yourDiv">
</div>

这应该很好用。在你的代码中你有:

function() {
          $(function() {

真的不知道你想用它做什么。删除一个函数()或使用我的代码。

这应该可以工作。当目标是<a>时,不要忘记使用preventDefault()

 $("#reset").click(function(e) {
     e.preventDefault();
     $("#RightPaneContainerDiv").html('<iframe src="open.php"></iframe>');
 });
function loadjscssfile(filename, filetype){
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

loadjscssfile("file.html", "html") //dynamically load "file.html" as a JavaScript file