我有一个远程网页,在该网页上我使用 CURL 和 DOMDocument 来检索图像的 src 属性。
我使用以下代码,在 PHP echo 中混合 JS
<?php
$toEcho = "";
$toEcho .= // some stuff here...
$toEcho.="
<script>
//I create the object
var img = new Image();
//I set the source with the PHP variable : I get an error because of unexpected token ":"
img.src = $imgsrc;
</script>"
echo $toEcho;
?>
我检查了来源,它是有效的,并且在我的浏览器中正确显示。
这可能是从哪里来的?
最佳答案
像这样设置源:
img.src = '$imgsrc';
关于javascript - 如何使用 base-64 源创建 Image 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31989030/