使用jquery选择器获取iframe内容 [英] Get iframe contents with a jquery selector

查看:1052
本文介绍了使用jquery选择器获取iframe内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何通过选择器访问iframe的内容?这样的事情:

Is there anyway to access an iframe's contents via a selector? Something like this:

$("iframe::contents .my-foo")

我不断访问我正在处理的项目的iframe内容和 $(iframe) .contents()。find(。my-foo)输入会变得有点乏味。

I'm constantly accessing an iframe's contents for a project I'm currently working on and $("iframe").contents().find(".my-foo") is becoming a bit tedious to type out.

如果此功能没有t开箱即可存在于jquery中,是否有提供此功能的插件?如果不是我怎么能写这样的插件?

If this feature doesn't exist in jquery out of the box, is there a plugin that provides this functionality? If not how could I write such a plugin?

推荐答案

我曾经遇到过这个问题,我发现这个问题很乏味。我从来没有找到像这样编写单个选择器的解决方案。

I had this issue once where I found it tedious. I never found a solution for how to write a single selector like that.

即便如此,选择器仍然很长。对我来说最明显的解决方案就是将其保存到变量。

Even so, the selector is still rather long. The most obvious solution to me is just save it to a variable.

var frame = $("iframe").contents();

frame.find(".my-foo")
...

这样更好吗?

这篇关于使用jquery选择器获取iframe内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆