Php 如何在不正确重新加载整个网页的情况下更改网页的一部分?
我试图调用javascript函数,通过导航栏更改php页面,而不重新加载整个页面,但我已经进入的关闭状态是我成功地通过按钮命令完成了这一操作,但是页面中的javascript被关闭了,我做错了什么Php 如何在不正确重新加载整个网页的情况下更改网页的一部分?,php,javascript,jquery,html,ajax,Php,Javascript,Jquery,Html,Ajax,我试图调用javascript函数,通过导航栏更改php页面,而不重新加载整个页面,但我已经进入的关闭状态是我成功地通过按钮命令完成了这一操作,但是页面中的javascript被关闭了,我做错了什么 <script src="js/jquery.min.js"></script> <script src="js/jquery-ui.min.js"></script> <script src="js/jquery-1.6.2.min.js"&g
<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/jquery-1.6.2.min.js"></script>
<script>
$(document).ready(function() {
$("#accordion").accordion();
$('#button_1, #button_2, #button_3, #button_4').click(function(){
var which_to_load = ( $(this).attr('id')+"" ).replace('button_', ''),
source_of_file = 'content'+which_to_load+'.php';
$('#content_box').load( source_of_file );
return false;
});
});
</script>
链接部分:
<div id="content_changing_buttons">
<form method="get" id="change_content_buttons" action="">
<p>
<li><input value="1" type="submit" id="button_1" name="page" /> Reggiani presents at frankfurt Light + Build 2012</a><br/><br /></li>
<li><input value="2" type="submit" id="button_2" name="page" /> Reggiani presents at frankfurt Light + Build 2012</a><br/><br /></li>
<li><input value="3" type="submit" id="button_3" name="page" /> Reggiani presents at frankfurt Light + Build 2012<br/><br /></li>
<li><input value="4" type="submit" id="button_4" name="page" /> Reggiani presents at frankfurt Light + Build 2012<br/><br /></li>
</p>
</form>
</div>
内容部分:
现在我已经按照建议做了,但是当我调用代码时,首先会显示默认的php页面,然后当我单击按钮更改页面的php端时,它工作了,但不知何故它关闭了其余的javascript,甚至我的accordion js和blinds js,它从另一个php页面引用的js突然关闭
任何人都可以建议如何解决此问题?您是否尝试过使用firebug进行调试?为了让javascript停止工作,通常php生成的响应必须包含错误的javascript本身。嗨,很抱歉,我对这一点很陌生,我不知道如何调试j查询本身,但是如果我上面的脚本初始化有任何错误,我想知道如何修复它,因为看起来,如果我使用一个函数,它就会工作,那么,如何在不重叠的情况下运行脚本的2个功能呢?实际上,您也可以使用chrome,只需按F12键,然后单击Console选项卡,然后刷新页面并单击离开,当页面停止工作时,控制台应该列出一些内容。您还可以安装它,它使用起来非常简单,并且有关于从php代码中打印到调试控制台的好例子。在javascript中,您只需键入console.loghello-world;但当以php形式加载外部页面以生成javascript console.log时,有时会变得很棘手。
<html>
<head>
<script language="javascript" type="text/javascript">
function showentry()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("right").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","details.php",true);//whatever the contents of file details.php displayed in right div
xmlhttp.send();
}
</script>
<style type="text/css">
#left{width:500px;height:100%; float:left;}
#right{width:500px; float:left;}
</style>
</head>
<div id="left">
<input type="button" name="GET" value="show" onclick="showentry()"/>
</div>
<div id="right">
</div>
</html>
<html>
<head>
<script language="javascript" type="text/javascript">
function showentry()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("right").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","details.php",true);//whatever the contents of file details.php displayed in right div
xmlhttp.send();
}
</script>
<style type="text/css">
#left{width:500px;height:100%; float:left;}
#right{width:500px; float:left;}
</style>
</head>
<div id="left">
<input type="button" name="GET" value="show" onclick="showentry()"/>
</div>
<div id="right">
</div>
</html>