Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
javascript中PHP内的IMG HTML标记_Javascript_Php_Jquery_Html - Fatal编程技术网

javascript中PHP内的IMG HTML标记

javascript中PHP内的IMG HTML标记,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我想在javascript中添加IMG src标记,将IMG源代码传递给js变量“content:”,然后再传递给php变量“$html:”。 我试过了,但是我得到了“未识别对象”错误。在本例中,是否有方法在javascript中添加img标记 $html .= ' <script type="text/javascript"> $(".example-p-1").on("click", function () { $.alert({

我想在javascript中添加IMG src标记,将IMG源代码传递给js变量“content:”,然后再传递给php变量“$html:”。 我试过了,但是我得到了“未识别对象”错误。在本例中,是否有方法在javascript中添加img标记

$html .= '
    <script type="text/javascript">
    $(".example-p-1").on("click", function () {
        $.alert({
            title: "You drawer is complete",
            content: "<div style="text-align:center"><img style="width:80px;height:80px" src="https://thedailyoutfits.com/wp-content/draw.jpg"><br></div>",
        });
    });
    </script>';
$html.='
$(“.example-p-1”)。在(“单击”,函数(){
美元警报({
标题:“你的抽屉完成了”,
内容:“
”, }); }); ';
您可以使用jQuery
$(this.attr(“src”)

您不能将JS传递到PHP中,因为PHP发生在页面加载之前,JS发生在加载之后,这可以通过AJAX或重新加载页面来完成

更新:
用单引号替换字符串中的所有双引号。这是因为外部字符串使用双引号,所以它基本上是不断打开和关闭的,所以使用单引号意味着它保持为单个字符串。

双引号周围有双引号。替换为单引号和转义

$html .= '<script type="text/javascript">

  $(".example-p-1").on("click", function () {
      $.alert({
          title: "You drawer is complete",
          content: \'<div style="text-align:center"><img style="width:80px;height:80px" src="https://thedailyoutfits.com/wp-content/draw.jpg"><br></div>\',
       });

   });
</script>";
$html.='
$(“.example-p-1”)。在(“单击”,函数(){
美元警报({
标题:“你的抽屉完成了”,
内容:\'
\', }); }); ";

好的选择是


$html.=请尝试在您的文件中使用以下代码,它将正常工作

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.3/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.3/jquery-confirm.min.js"></script>
    <?php

$html = "";
$html .= '<script type="text/javascript">

  jQuery(".example-p-1").on("click", function () {
                    jQuery.alert({
                        title: "You drawer is complete",
                        content: "<div style=text-align:center><img style=width:80px;height:80px; src=https://thedailyoutfits.com/wp-content/draw.jpg><br></div>",

                    });

                });


        </script>';

echo $html;
        ?>


有人能至少给我这个问题的参考解决方案/链接吗?我有正常的文本内容,但没有img src标签。@Sandeeptte标签指的是什么?编辑:只需将内容字符串中的所有“替换为”?@Sandeeptte太棒了!
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.3/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.3/jquery-confirm.min.js"></script>
    <?php

$html = "";
$html .= '<script type="text/javascript">

  jQuery(".example-p-1").on("click", function () {
                    jQuery.alert({
                        title: "You drawer is complete",
                        content: "<div style=text-align:center><img style=width:80px;height:80px; src=https://thedailyoutfits.com/wp-content/draw.jpg><br></div>",

                    });

                });


        </script>';

echo $html;
        ?>