jQuery中的contentDocument [英] contentDocument in jQuery

查看:88
本文介绍了jQuery中的contentDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下js脚本来访问对象内的元素(SVG - < object data =bbbbbb.svgtype =image / svg + xmlid =alphasvgwidth = 100%height =100%>< / object>

I have the following js script to access elements inside a object (SVG - <object data="bbbbbb.svg" type="image/svg+xml" id="alphasvg" width="100%" height="100%"></object> )

jQuery(document).ready(function($) {

    $(window).load(function () {


        var a = document.getElementById("alphasvg");
        var svgDoc = a.contentDocument; 
        var delta = svgDoc.getElementsByTagName("path");    
        $(delta).click(function() {

            //do stuff

        })

    });
});

我想使用jQuery访问元素和标签。我完全停留在contentDocument部分。如何将其转换为jQuery,以便我可以使用attr等?

I want to use jQuery to access the elements and tags. I'm completely stuck on the contentDocument part. How can I convert this to jQuery so I can use attr etc?

我希望能够访问和修改jQuery中的属性,而不必使用传统的js方法我不熟悉。

I want to be able to access and modify attributes in jQuery instead of having to use the traditional js methods which I am unfamiliar with.

有人可以帮助我吗?

万分感谢。

推荐答案

喜欢这样:

$(svgDoc).find("whatever").doWhatever();

在此演示此处代码。请注意,我已使用< iframe> 进行演示,因此第一个网址将起作用,如果您尝试运行,第二个网址会给您权限被拒绝错误小提琴。

Demo here and code here. Note that I've used an <iframe> for demonstration hence the first URL will work, second will give you "permission denied" error if you try to run the fiddle.

这篇关于jQuery中的contentDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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