这jQuery隐藏功能只是不想工作 [英] This jQuery hide function just does not want to work
问题描述
这是我的浏览器看到的HTML。我想隐藏 div.embed
元素:
Here's the HTML that my browser sees. I want to hide the div.embed
element:
<div id="video_div">
<img src="http://i2.ytimg.com/vi/ERF9lCf86I8/hqdefault.jpg" style="width: 200px; ">
<div class="embed">
<object width="300" height="194"><param name="wmode" value="opaque"><param name="movie" value="http://www.youtube.com/v/ERF9lCf86I8?version=3">
<param name="allowFullScreen" value="true">
<param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/ERF9lCf86I8?version=3" type="application/x-shockwave-flash" width="300" height="194" allowscriptaccess="always" allowfullscreen="true" wmode="opaque">
</object>
</div>
</div>
这里是我的application.js代码,用它相应的嵌入视频动态替换链接,显示缩略图,并且未成功隐藏视频:
Here's my application.js code to dynamically replace a link with its corresponding embedded video, display the thumbnail, and unsuccessfully hide the video:
$(document).ready(function() {
$('a.oembed').embedly({maxWidth:300,'method':'replace'}).bind('embedly-oembed', function(e, oembed){
$("#video_div").prepend($("<img>", { src: oembed.thumbnail_url, width:200 }));
});
$('div.embed').hide();
});
这种隐藏方法不起作用真的很奇怪。任何想法为什么?
It's really weird that this hide method does not work. Any ideas why?
推荐答案
我期望上面的代码 hide
呼叫失败,呼叫根本没有执行。如果我插入假的嵌入的
插件,它可以工作: http://jsbin.com/ucuru4/2
I expect the code above the hide
call is failing and the call isn't getting executed at all. If I put in a fake embedly
plug-in, it works: http://jsbin.com/ucuru4/2
我建议在调试器中单步执行代码。 Chrome,Safari,Opera和IE8都有内置的调试器。有Firefox的Firebug,以及VS.Net的免费版本,用于在以前版本的IE上进行调试。
I recommend single-stepping through the code in a debugger. Chrome, Safari, Opera, and IE8 all have built-in debuggers. There's Firebug for Firefox, and the free edition of VS.Net for debugging on previous versions of IE.
如果代码没问题,但是您发现 embedly
call间歇性失败,可能最好将它包装在 try / catch
块中。
If the code is okay but you find that the embedly
call is failing intermittently, may be best to wrap it in a try/catch
block.
这篇关于这jQuery隐藏功能只是不想工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!