使用attr()方法的jQuery对象/嵌入元素问题 [英] JQuery object / embed element issue with attr() method

查看:87
本文介绍了使用attr()方法的jQuery对象/嵌入元素问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据点击事件交换此嵌入元素的src值.
它可以按预期在Firefox和Opera中运行,但不能在Safari,Chrome或IE中运行.

I am trying to exchange the value of this embed element's src value, dependent of the click event.
It works in firefox and opera as intended, but not in safari, chrome, or IE.

$('.scrollableArea a').click(function() {
//retract id from selected anchor, and create + append new video parameter values.
var newVideoVal = 'http://www.youtube.com/v/' + $(this).attr("id") + '?version=3&autoplay=1';
$('#gallery_content object param').attr('value', newVideoVal);
$('#gallery_content object embed').attr('src', newVideoVal);
});

如果我在点击事件功能中输入 console.log 以下内容.

If i console.log the following in the click event function..

console.log($('#gallery_content embed').attr("src"));

对于每个单击事件,控制台返回src的值,并带有交替的锚点ID值,例如
http://www.youtube.com/v/videoidhere?version=3&autoplay=1

The console returns, for each click event - the value of src, with alternating anchors id value, eg.
http://www.youtube.com/v/videoidhere?version=3&autoplay=1

这是浏览器问题吗?
操作对象/嵌入元素有问题吗?
难道我做错了什么? (大概!)

Is this a browser issue?
An issue with manipulating the object / embed element?
Am i doing something wrong? (probably!)

推荐答案

感谢大家,我已经从这些建议中衍生出一些组合逻辑来解决我的解决方案.

Thanks to everyone, I've resolved my solution with a bit of combined logic, derived from these suggestions.

$('.scrollableArea a').click(function() {   
    var newObjElement = '<object style="width:580px;height:386px;"><param name="movie" value="http://www.youtube.com/v/'+this.id+'?version=3&autoplay=1"><embed src="http://www.youtube.com/v/'+this.id+'?version=3&autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="580" height="386"></object>';

    mainArea.html(newObjElement);
});

*记下this.id.

这在大多数浏览器(safari,opera,chrome,firefox,ie8/9)中都适用,但ie6和7除外(尽管与ie6无关)

This works in most browsers, (safari, opera, chrome, firefox, ie8 / 9) with exception of ie6, and 7. (although not concerned for ie6)

关于为什么/如何解决ie7问题的任何想法?

Any ideas as to why / how to resolve the issue for ie7?

干杯!

这篇关于使用attr()方法的jQuery对象/嵌入元素问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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