2014-09-10 112 views
-1

嗨html文件,我想包括下面的代码我做了链接点击这里文件,但它不是在我的HTML网页的工作如何包括点击链接

这里是低于

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

这里我错了,在下面的代码

我如何能实现我的输出

回答

1

你是JavaScript的处理程序绑定到的链接要包括在你的HTML链接之前。

点击事件触发后,您会延迟反应,直到DOM准备就绪 - 在点击链接时DOM不可能准备就绪。

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

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

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

我看到的第一件事是

$(函数(){

当你做一个。点击功能,不要调用现成功能,使你的代码是这样的:

 $("#reset").click(function() { 

       $("#RightPaneContainerDiv").html('<iframe src="open.php"></iframe>'); 

    }); 
0
<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() { 

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

+0

当我尝试这种代码的,显示消息禁止访问 – 2014-09-10 13:51:40

+0

你能告诉我更多你的代码? – 2014-09-10 13:54:27

+0

这里是我的phpfile <?php echo“shakti”; ?> – 2014-09-10 14:01:51

0

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

$("#reset").click(function(e) { 
    e.preventDefault(); 
    $("#RightPaneContainerDiv").html('<iframe src="open.php"></iframe>'); 
}); 
0
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