嘿,我有这段代码,但它没有按我想要的那样工作
function showcode() {
if ($('#sampleeditor').text() != '') {//check if the div is not empty => not working
var orgcontent = document.getElementById('sampleeditor').innerHTML;//get the content of the div
var copiedcontent = document.getElementById('contentcode').innerHTML = orgcontent;//place the content in the target div || the issue here is that the content is shown as it is|| I want it to be a text of the code
} else {
document.getElementById('contentcode').innerHTML = "Nothing to show";//if the original div is empty show this text
}
$("#Showcode").modal('show');// the modal where the contentcode is placed.
}
基本上我希望代码获取 div(sampleeditor) 的内容并将它们作为文本显示在 modal(showcode) 内的另一个 div (contentcode) 中。
此代码按原样复制内容。例如。如果我在第一个 div 中有一个图像,它会在另一个 div 中显示为图像。我希望它是这样的div class="divimage" id="WNI4022"><img src="empty.jpg" width="100px" height="100px"></div>