gpt4 book ai didi

jquery - 在 iframe 内的链接中应用 jquery

转载 作者:太空宇宙 更新时间:2023-11-04 09:58:25 25 4
gpt4 key购买 nike

我有以下工作代码,仅在 iframed 文本区域中应用一些样式:

`$("#ctl00_m_g_f2a05a6e_efee_4fc1_9c2f_7bb3efaa99a9_ctl00_txtDescricao_iframe").contents().find("body").attr("style","font-size: 11pt !important; font-family: 'Segoe UI', 'Segoe UI Web', 'Segoe UI Symbol', 'Helvetica Neue', Arial, sans-serif !important; background-color: #FFFFFF !important; border: 0px !important;")`

我有以下无效代码,当它找到链接时应该添加图像:

$('#ctl00_m_g_f2a05a6e_efee_4fc1_9c2f_7bb3efaa99a9_ctl00_txtDescricao_iframe a').append('<img id="LinkImage" src="http://server/Link.png" />')

试图将两个代码放在一起但没有运气。

更新:

var $frameContents = $("#ctl00_m_g_f2a05a6e_efee_4fc1_9c2f_7bb3efaa99a9_ctl00_txtDescricao_iframe").contents();
//works
$frameContents.find("body").attr("style","font-size: 11pt !important; font-family: 'Segoe UI', 'Segoe UI Web', 'Segoe UI Symbol', 'Helvetica Neue', Arial, sans-serif !important; background-color: #FFFFFF !important; border: 0px !important;");
//dont work
$frameContents.find("a").append("<img id='LinkImage' src='http://server/Link.png' />");
//dont work
$frameContents.find("img").attr("style","border: 1px #EDEDED solid; padding: 8px; margin-top: 5px; margin-bottom: 20px;");

生成的代码: enter image description here

最佳答案

您的第一个示例是在 contents() 内搜索对于元素,但第二个示例是使用无效的后代选择器。

您需要使用 $(iframeSelector).contents().find('a')收集所有<a>在 iframe 中

将两者结合起来只是存储对内容的引用

var $frameContents = $("#ctl00_m_g_f2a05a6e_efee_4fc1_9c2f_7bb3efaa99a9_ctl00_txtDescription_iframe").contents();

$frameContents.find('body').attr('style', '....');
$frameContents.find('a').append('.....');
// OR
$frameContents.find('body').attr('style', '....').find('a').append('.....');

关于jquery - 在 iframe 内的链接中应用 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38526004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com