简体   繁体   English

将javascript innerhtml变量传递给php

[英]passing javascript innerhtml variable to php

Really need your help, I have the below javascript code: 确实需要您的帮助,我有以下javascript代码:

    document.querySelector('#btnCrop').addEventListener('click', function(){
        var img = cropper.getDataURL();

        document.querySelector('.cropped').innerHTML += img;
    })

The "img" has a value: “ img”具有一个值:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMYAAADGCAYAAACJm/9dAAAgAElEQVR4Xuy9B6CdZZUuvE56771AQgqEGgKEkNCrgoAFRFQQHevM+Ht/nTsX5/7XmXFm1Jlx7HVGZSxIN0iXIqFLSEgIkALpvScnvZ/7rPaW7/v2PicQEPzdGs7eX3nLeldf611vAxE14d+b/rn2/DPos5ddSN26

so what is does in php is to display it via: 所以在php中通过以下方式显示它:

$img = (div class="cropped" style="float: left;margin-top:-653px;margin-left: 630px;border:1px solid violet")(/div)

What I need is to display it without div. 我需要的是不带div显示它。 Just the value of the "img". 只是“ img”的值。

Replace 更换

document.querySelector('.cropped').innerHTML += img;

with something like this: 像这样:

document.write("<img src=\"" + img + "\" style=\"\">");

That will just write it in document. 那将只写在文档中。 But basically it's the same when extending it to something. 但是将其扩展到某些东西时基本上是相同的。 Something like this is more what you want I guess: 我猜想这样的东西更多是您想要的:

$('img#ID').attr('src', img);

(This wil set the src value (Base64) in the image. If you want you could hide it at first and then use $().show() to make the image visible again. (这将在图像中设置src值(Base64)。如果需要,可以先将其隐藏,然后使用$()。show()使图像再次可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM