[英]How to get value of WYSIWYG and insert it in textarea Tag by Javascript only?
how to get the value of WYSIWYG and insert it in Textarea Tag by Javascript only?如何仅通过 Javascript 获取 WYSIWYG 的值并将其插入 Textarea 标签?
<script> // insert value in texatarea function frm() { var x = document.getElementById("tgt").contentWindow.document.getElementsByTagName("body").value; document.getElementById("val1").innerHTML = x; } //////////////////////////////////////////////////////// // WYSIWYG2 /////////////////////////////////////////////////////// var showingSourceCode = false; var isInEditMode= true; function enableDesignMode(){ ritchTextFiled.document.designMode='on'; } function exeCmd(command){ ritchTextFiled.document.execCommand(command,null,false); } function execCommandWithArg(command,arg){ ritchTextFiled.document.execCommand(command,null,arg); } function toggleSource(){ if(showingSourceCode){ ritchTextFiled.document.getElementsByTagName('body')[0].innerHTML= ritchTextFiled.document.getElementsByTagName('body')[0].textContent; showingSourceCode=false; }else{ ritchTextFiled.document.getElementsByTagName('body')[0].textContent= ritchTextFiled.document.getElementsByTagName('body')[0].innerHTML; showingSourceCode=true; } } function toggleEdit(){ if(isInEditMode){ ritchTextFiled.document.designMode='off'; isInEditMode=false; }else{ ritchTextFiled.document.designMode='on'; isInEditMode=true; } }
<;DOCTYPE html> <html> <head> <body> <body onload="enableDesignMode();"> <textarea name="textval1" id="val1"> </textarea> <iframe id='tgt' name="ritchTextFiled" onkeyup="frm()" > </iframe> </body> </html>
the best solution found until now by Javascript is:到目前为止,Javascript 找到的最佳解决方案是:
var iframe = document.getElementById("tgt");
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
document.getElementById("val1").innerHTML=innerDoc.body.innerHTML;
Thank you.谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.