简体   繁体   English

使用jQuery将文本添加到iframe

[英]adding text into iframe with jquery

I have an HtmlEditor from asp controltoolkit. 我有一个来自asp controltoolkit的HtmlEditor。
That creates an iframe with a couple things i need (bold letter, etc). 这会创建一个iframe,其中包含我需要的一些内容(粗体字母等)。
I need to add text to that iframe with jquery. 我需要使用jquery向该iframe添加文本。
so long i have this. 很久我有了这个。

$('#<%= tbDescripcionInsert.ClientID %>').contents().text(textoMercancia.substring(15, textoMercancia.length));

My problem is that the things im using from the editor (bold letter etc) disappear when i add the text from jquery. 我的问题是,当我从jquery添加文本时,即时通讯从编辑器中使用的东西(粗体字母等)消失了。

What can it be? 会是什么
What is the best way to add text into an iframe with jquery? 使用jquery将文本添加到iframe的最佳方法是什么?

Thank you very much. 非常感谢你。

the problem is that 问题是

  .text('blahblah') 

replaces the text so you must use 替换文本,因此您必须使用

 .append('blahblah') 

or some similar command 或一些类似的命令

EDIT seeing your post this might be more effective 编辑看到您的帖子可能更有效

  $('#<%= tbDescripcionInsert.ClientID %>').contents().find('body').append('blahblah')

如果要处理标记,而不仅仅是文本,请使用html()而不是text()。

Try something like: 尝试类似:

var d = $("#someFrame")[0].contentWindow.document; var d = $(“#someFrame”)[0] .contentWindow.document; // contentWindow works in IE7 and FF d.open(); // contentWindow在IE7和FF中运行d.open(); d.close(); d.close(); // must open and close document object to start using it! //必须打开和关闭文档对象才能开始使用它!

// now start doing normal jQuery: //现在开始使用普通的jQuery:

$("body", d).append("ABC"); $(“ body”,d).append(“ ABC”);

Thank you all for your help. 谢谢大家的帮助。

I found a way to solve this: 我找到了解决此问题的方法:

$('#<%= tbDescripcionInsert.ClientID %>_ctl02_ctl00').contents().children().children('body').html(textoMercancia.substring(15, textoMercancia.length));

this way i can access the exact part of the iframe where the information is supossed to be loaded. 通过这种方式,我可以访问iframe的确切部分,该部分应该可以加载信息。 hope this help someone in the future. 希望这对以后的人有所帮助。

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

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