jQuery 正确更改了源代码,但未更改渲染的页面结果。 (有jsFiddle证明)
这是我的 jQuery:
$("object").each(function(){
video_url = $(this).find('embed').attr('src');
new_video_url = video_url+"&autohide=1&modestbranding=1&showinfo=0&theme=light";
$(this).find('embed').attr('src', new_video_url);
$(this).find('param:eq(0)').val(new_video_url);
$(this).find('embed').before('<param name="autoplay" value="1"><param name="showinfo" value="1"><param name="modestbranding" value="1"><param name="hd" value="1"><param name="color" value="white"><param name="autohide" value="1">');
});
这是 jQuery 之前的代码的样子:
<object width="500" height="371">
<param name="movie" value="http://www.youtube.com/v/ISeQBRUa8xQ&rel=0&egm=0&showinfo=0&fs=1">
<param name="wmode" value="transparent">
<param name="allowFullScreen" value="true">
<embed
src="http://www.youtube.com/v/ISeQBRUa8xQ&rel=0&egm=0&showinfo=0&fs=1"
type="application/x-shockwave-flash"
width="500"
height="371"
allowfullscreen="true"
mode="transparent"
>
</object>
这是执行 jquery 之后的样子。
<object width="500" height="371">
<param name="movie" value="http://www.youtube.com/v/ISeQBRUa8xQ&rel=0&egm=0&showinfo=0&fs=1&autohide=1&modestbranding=1&showinfo=0&theme=light">
<param name="wmode" value="transparent">
<param name="allowFullScreen" value="true">
<param name="autoplay" value="1">
<param name="showinfo" value="1">
<param name="modestbranding" value="1">
<param name="hd" value="1">
<param name="color" value="white">
<param name="autohide" value="1">
<embed
src="http://www.youtube.com/v/ISeQBRUa8xQ&rel=0&egm=0&showinfo=0&fs=1&autohide=1&modestbranding=1&showinfo=0&theme=light"
type="application/x-shockwave-flash"
width="500"
height="371"
allowfullscreen="true"
wmode="transparent"
>
</object>
即使 HTML 代码已成功更改,页面的呈现也不会显示更新后的代码。
这是证明该问题的 jsFiddle: http://jsfiddle.net/4kQYy/4/
如果您检查检查器中的第二个 YouTube 视频,您会发现它实际上 100% 正确地注入了代码,但页面渲染并未反映更新。怎么可能呢?您在源代码中看到的肯定就是您在屏幕上看到的吗?帮助!
Here is my jQuery:
$("object").each(function(){
video_url = $(this).find('embed').attr('src');
new_video_url = video_url+"&autohide=1&modestbranding=1&showinfo=0&theme=light";
$(this).find('embed').attr('src', new_video_url);
$(this).find('param:eq(0)').val(new_video_url);
$(this).find('embed').before('<param name="autoplay" value="1"><param name="showinfo" value="1"><param name="modestbranding" value="1"><param name="hd" value="1"><param name="color" value="white"><param name="autohide" value="1">');
});
Here is what the code looked like before the jQuery:
<object width="500" height="371">
<param name="movie" value="http://www.youtube.com/v/ISeQBRUa8xQ&rel=0&egm=0&showinfo=0&fs=1">
<param name="wmode" value="transparent">
<param name="allowFullScreen" value="true">
<embed
src="http://www.youtube.com/v/ISeQBRUa8xQ&rel=0&egm=0&showinfo=0&fs=1"
type="application/x-shockwave-flash"
width="500"
height="371"
allowfullscreen="true"
mode="transparent"
>
</object>
Here is what it looks like after the jquery has been executed.
<object width="500" height="371">
<param name="movie" value="http://www.youtube.com/v/ISeQBRUa8xQ&rel=0&egm=0&showinfo=0&fs=1&autohide=1&modestbranding=1&showinfo=0&theme=light">
<param name="wmode" value="transparent">
<param name="allowFullScreen" value="true">
<param name="autoplay" value="1">
<param name="showinfo" value="1">
<param name="modestbranding" value="1">
<param name="hd" value="1">
<param name="color" value="white">
<param name="autohide" value="1">
<embed
src="http://www.youtube.com/v/ISeQBRUa8xQ&rel=0&egm=0&showinfo=0&fs=1&autohide=1&modestbranding=1&showinfo=0&theme=light"
type="application/x-shockwave-flash"
width="500"
height="371"
allowfullscreen="true"
wmode="transparent"
>
</object>
Even though the HTML code has successfully changed, the rendering of the page does not show the updated code.
Here is a jsFiddle proving the issue: http://jsfiddle.net/4kQYy/4/
If you inspect the second youtube video in your inspector, you'll see that it actually gets the code injected 100% correctly, yet the page render does not reflect the update. How can that be? Surely what you see in source code is what you see on screen? Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是闪存专家,但我的逻辑是,你想做的事情是行不通的。在我看来,会发生以下步骤:
您可以做的就是移动整个 Flash 实例flash实例化过程到javascript。这意味着您生成了整个对象标签。或者您分离对象标签,进行自定义并再次重新插入。我更新了您的 fiddle 中的代码
我知道这并不适用于所有情况,特别是如果父母有多个孩子,但它应该让您有一个大概的了解。
I'm not a flash expert but my logic says, that what you are trying to do can not work. What happens in my opinion are the following steps:
What you could do is either move the whole flash instantiation process to javascript. That means you generate the whole object tag. Or you detach the object tag, make your customizations and reinsert it again. I updated the code in your fiddle
I know that this does not work in every condition especially, if the parent has more than one child, but it should give you a general idea.