繁体   English   中英

如何获取 WYSIWYG 的值并将其仅插入 Javascript 的 textarea 标签中?

[英]How to get 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>
我尝试了互联网上的大多数解决方案,但都使用 jquery 或 javascript 不起作用,请尝试仅通过 javascript 找到解决方案。

到目前为止,Javascript 找到的最佳解决方案是:

   var iframe = document.getElementById("tgt");
   var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
   document.getElementById("val1").innerHTML=innerDoc.body.innerHTML;

谢谢你。

暂无
暂无

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

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