【问题标题】:jquery - textarea and iframe value is emptyjquery - textarea 和 iframe 值为空
【发布时间】:2016-03-13 02:17:27
【问题描述】:

这是我们所知道的简单的richtexteditor。 textarea 不包括 iframe。但我需要获取 iframe 的内容。

var textfield = $("#richTextField").html();		   
var textfield = $("#myTextArea").html();
<textarea style="display: none" class="myTextArea" name="myTextArea" id="myTextArea" cols="100" rows="14"></textarea>
<iframe name="richTextField" class="richTextField" id="richTextField" onload="window.frames['richTextField'].document.designMode='on';" ></iframe>
		

但是,textarea 和 iframe 的值都是空的。我如何从 textarea 或 iframe 获取内容。 感谢阅读。

【问题讨论】:

    标签: javascript jquery ajax iframe


    【解决方案1】:

    iframe 取决于它是否在同一个域中。如果它是不同的域,您将无法从中提取内容。

    对于文本区域使用.val()

    var textfield = $("#myTextArea").val();
    

    【讨论】:

    【解决方案2】:

    我找到并解决了。非常感谢

    function getFrameContents(){
       var iFrame =  document.getElementById('id_description_iframe');
       var iFrameBody;
       if ( iFrame.contentDocument ) 
       { // FF
         iFrameBody = iFrame.contentDocument.getElementsByTagName('body')[0];
       }
       else if ( iFrame.contentWindow ) 
       { // IE
         iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
       }
        alert(iFrameBody.innerHTML);
     }

    来自here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多