简体   繁体   English

如何获得HTML DIV值

[英]How to get HTML DIV value

I'm trying to do screen shot paste in my website using firefox. 我正在尝试使用Firefox在我的网站中粘贴屏幕截图。 It can be done easily by giving the div as contenteditable='true' . 通过将div设置为contenteditable='true'可以轻松contenteditable='true'

html html

<Html>
<Head>
<Title>Screen Shot Example</Title>
<style type="text/css">
#apDiv1 {
    position:absolute;
    width:258px;
    height:165px;
    z-index:1;
    left: 71px;
    top: 59px;
}
</style>
</Head>

<Body>
<div id="apDiv1" contenteditable='true'>Paste Test</div>
</Body>
</Html> 

I can paste images from clipboard to particular div. 我可以将图像从剪贴板粘贴到特定的div。 Now the issue starts, how do I get the value from the div. 现在问题开始了,如何从div获取值。 For an example my user paste screenshot in the div and i want it to be save in db. 例如,我的用户将屏幕截图粘贴到div中,我希望将其保存在db中。 If it normal textbox I can get the textbox value. 如果它是正常的文本框,我可以获取文本框值。 Is there any way I can convert the DIV to image. 有什么办法可以将DIV转换为图像。 Any advice and any referral links is highly appreciated. 任何建议和任何推荐链接都将受到高度赞赏。

document.addEventListener('DOMContentLoaded', function(){ 
    var text = document.getElementById('apDiv1').innerText;
}, false);

To replace the div : 替换div

document.addEventListener('DOMContentLoaded', function(){ 
    var el = document.getElementById("apDiv1");
    var img = document.createElement("img");
    img.setAttribute('src', '...');
    el.parentNode.replaceChild(el, img);
}, false);

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

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