你好,我是 php 菜鸟。但我有这样的东西:
<div id="signupbox">
<!--A lot of stuff-->
</div>
所以我在上面有一个 php 脚本,用于检查 $get 变量是否为 activation_success
,所以我会回显 JavaScript 来查找 #signupbox 并更改 innerHTML,但我还想包含一个名为 login.php
的文件。在#signupbox 内。
问题是,如果我使用 javascript 更改了 div 的innerHTML,包含的 .php 文件也会消失。
我可以通过什么方式更改innerHTML并在其中包含.php文件?
我想包括login.php
文件,因为它就像一个片段,所以我可以将它包含在其他地方,如果我想更改,我可以更改包含的文件。
我要做的是echo('<script>$("#signupbox").html("Thank you!");</script>' . include("login.php"));
最佳答案
使用load() jQuery 方法:
html = $('#signupbox').html(); // save the previous html
$('#signupbox').load('login.php', function(){
$(this).prepend(html); // add the previous html in the beginning
});
关于PHP - 检查 $get 变量然后清除 div 并包含 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18461956/