gpt4 book ai didi

javascript - 使用 jQuery 和 php 打印为 html

转载 作者:行者123 更新时间:2023-11-28 06:48:29 25 4
gpt4 key购买 nike

我有这段代码来显示数据库中的一些 html :

$("#menuOverlay").append('<?php include('aggiungiPaginaComp.php');?>');

它正在工作,来自浏览器的源文件:

$("#menuOverlay").append('<form id="aggiungiPagina"
name="aggiungiPagina"
action="script/aggiungiPagina.php"
method="post">

<tablestyle="width:100%;">
<tr>
<td>NomePagina</td>
<td><inputsize="30"
maxlength="30"
placeholder="Inseriscinomepagina"
autofocus
required
type="text"
name="nomePagina"
id="nomePagina"></td>
</tr>
<tr>
<td>Descrizione</td>
<td><inputsize="50"
maxlength="200"
placeholder="Inseriscidescrizione"
required
type="text"
name="descrizione"
id="descrizione"></td>
</tr>

</table>
<divid="scrisciaBtnForm">
<inputclass="btnMenu"type="submit"value="invia"/>
</div>
</form>');

但是 div #menuOverlay 是空白的..:

$("#menuOverlay").append('<Button> ciao </Button>');

有效,为什么?抱歉英语不好。

最佳答案

您应该在 PHP 中对页面进行 HTML 编码(这样双引号就不会导致错误),然后在 JS 中对其进行 html 解码。如果你使用 jQuery 这应该可以工作:

String.prototype.htmlDecode = function(){
return $('<div/>').html(this).text();
};

$("#menuOverlay").append("<?php
ob_start();
include('aggiungiPaginaComp.php');
$page = ob_get_clean();
echo htmlentities($page);
?>".htmlDecode());

关于javascript - 使用 jQuery 和 php 打印为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33190152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com