gpt4 book ai didi

javascript - .append() 方法不会正确附加 php

转载 作者:行者123 更新时间:2023-11-30 17:07:54 24 4
gpt4 key购买 nike

我有一个保存为 menu.php 的导航栏。然后在我的主页中我创建了一个名为“Inject”的按钮。这应该在单击时附加一个 php include 标记。这是我的代码:

$(document).ready(function(){
$("#inject").click(function(){
$("body").append("<?php include '../menu.php'; ?>");
});
});


<body>


<div class="container">
<div class="jumbotron landing">
<h1 class="text-center"><span class="text-primary">Hex to Rgb converter V1.0 </span></h1>
</div>
<div id="inject" class="btn btn-danger">Inject</div>
<h1>Enter hex code without <kbd>#</kbd> and press <kbd>Enter</kbd></h1>
<kbd class="h3">#</kbd><span class="h4 bg-primary">+</span><input type="text" maxlength="6" id="hex" class="text-warning bg-info h3 img-rounded" pattern="[A-Fa-f]{6}" title="Type a hex code please">
<h1>Rgb</h1>
<p id="rgb" class="h4 text-primary bg-success"></p>
</div>
</body>

我在 js 控制台(chromium)上遇到的问题是“Uncaught SyntaxError: Unexpected identifier”php include 标签在没有被 javascript 插入时可以正常工作。有什么想法吗?

最佳答案

我可能会为此使用 ajax,但要在您的 js 代码中包含任意字符串,您必须对其进行正确编码。

$("body").append(<?php echo json_encode(file_get_contents('../menu.php')); ?>);

关于javascript - .append() 方法不会正确附加 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27581904/

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