Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery insertAfter在html内部使用php变量_Php_Jquery_Html_Wordpress - Fatal编程技术网

使用jquery insertAfter在html内部使用php变量

使用jquery insertAfter在html内部使用php变量,php,jquery,html,wordpress,Php,Jquery,Html,Wordpress,我有一个类似这样的php函数 function get_some_info() { $location = other_function_that_returns_a_string(); return <<<HTML <script> $("<h1> <?php echo $location ?> </h1>").insertAfter("header"); </script> HTML; } 函数获取一些

我有一个类似这样的php函数

function get_some_info() 
{

$location = other_function_that_returns_a_string();
 return <<<HTML
<script>

$("<h1> <?php echo $location ?> </h1>").insertAfter("header");

</script>
HTML;
}
函数获取一些信息()
{
$location=返回字符串()的其他函数;

return问题在于您使用了语法

您不必在其中使用

这很好:

$("<h1> $location </h1>").insertAfter("header");
$(“$location”)。插入后面(“标题”);
以下是我测试的代码:


标题

如果您硬编码
$位置
?比如
$(“test”).insertAfter(“header”);
-我怀疑jquery选择器会找到类似的东西。还有
是的,那么近,那么远。一旦我们得到了herdoc的怪癖,一切都会顺利进行。这是我需要看到的
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
    Header
</header>

<?php
function other_function_that_returns_a_string(){
    return "A string";
}

function get_some_info(){
    $location = other_function_that_returns_a_string();    // Will be "A string"
    return  <<<HTML
<script>
$("<h1> $location </h1>").insertAfter("header");
</script>
HTML;
}

echo get_some_info();

?>