Joe*_*ank 2 jquery jquery-selectors
什么是在当前文档中找到给定"div.myClass"元素的最佳方法,以及它(以及它们的嵌套iframe)可能具有的任何iframe?
谢谢
如果帧访问不受同一原始策略的限制:
function getElem(selector, $root, $collection) {
if (!$root) $root = $(document);
if (!$collection) $collection = $();
// Select all elements matching the selector under the root
$collection = $collection.add($root.find(selector));
// Loop through all frames
$root.find('iframe,frame').each(function() {
// Recursively call the function, setting "$root" to the frame's document
getElem(selector, $(this).contents(), $collection);
});
return $collection;
}
// Example:
var $allImageElements = getElem('img');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2878 次 |
| 最近记录: |