你好,我是php中的一个菜鸟。但我有这样的事情:
<div id="signupbox">
<!--A lot of stuff-->
</div>
所以我有一个php脚本,上面是检查一个$get变量是否是activation_success
,所以我会回显一个javascript来查找#signupbox并更改innerHTML,但是我也希望在#signupbox中包含一个名为login.php
的文件。
问题是,如果我使用javascript更改div的innerHTML,所包含的.php文件也将消失。
以什么方式更改innerHTML并在其中包含一个.php文件?
我想要包含login.php
文件,因为它就像一个片段,所以我可以将它包含在其他地方,如果我想要更改,我可以更改所包含的文件。
我要做的是echo('<script>$("#signupbox").html("Thank you!");</script>' . include("login.php"));
发布于 2013-08-27 01:53:33
使用负载() jQuery方法:
html = $('#signupbox').html(); // save the previous html
$('#signupbox').load('login.php', function(){
$(this).prepend(html); // add the previous html in the beginning
});
发布于 2013-08-27 01:44:51
因此,如果我的理解是正确的,那么您想要更改teh #box div的innerHTML,但保留由您的包含生成的teh代码吗?
你为什么不在#盒子里再做一个更小的div,只把你想要的东西放在里面,然后只改变里面的div.
<div id="box">
<div id="innerBox">
<!--all the stuff that was in the #box, except for the include -->
</div>
<?php include "myinclude.php"; ?>
</div>
发布于 2013-08-27 01:49:49
include.php没有消失,php是服务器端语言。您的代码正在删除现有内容和重写。“.html()
”将删除目标内容中的所有内容,在客户端执行.html()
功能时,include.php
内容将被删除,同时在javascript中添加更多内容,
$('#signbox').append('Thank you!');
而不是
$('#signbox').html('Thank you!');
希望这能帮上忙。
https://stackoverflow.com/questions/18461956
复制