在javascript中PHP内的IMG HTML标签

I want to add IMG src tag in javascript to pass the img source to a js variable 'content:' which is then passed to a php variable '$html:'. I tried but i get the error 'unidentified object' error. Is there a way to add the img tag in javascript in this case.

$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>';

You can retrieve the img src using jQuery $(this).attr("src")

You can't pass JS into PHP because PHP occurs before the page load and JS occurs after, this could be done via AJAX or if you reload the page.

UPDATE: Replace all double quotes within the string with single quotes. This is because the outer string uses double quotes so its basically being opened and closed constantly, so using single quotes means it stays as a single string.

You have double-quotes around double-quotes. Replace to single-quotes and escape.

$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>";

Good alternative is HEREDOCS

$html .= <<< JS
    <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>
JS;// Do not indent this ending tag.

<<< JS can be any text as long as it matches JS;

Please try to use following code in your file and it will work.

<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;
        ?>