这个 jQuery 隐藏功能只是不想工作
这是我的浏览器看到的 HTML。我想隐藏 div.embed
元素:
<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 代码,用于动态地将链接替换为其相应的嵌入视频,显示缩略图,并成功隐藏视频:
$(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();
});
这种隐藏真的很奇怪方法不起作用。有什么想法吗?
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>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我预计
hide
调用上方的代码会失败,并且该调用根本不会被执行。如果我放入一个假的embedly
插件,它就会起作用:http://jsbin。 com/ucuru4/2我建议在调试器中单步执行代码。 Chrome、Safari、Opera 和 IE8 都有内置的调试器。有用于 Firefox 的 Firebug,以及用于在早期版本的 IE 上进行调试的 VS.Net 免费版本。
如果代码没问题,但您发现
embedly
调用间歇性失败,则最好将其包装在try/catch
块中。I expect the code above the
hide
call is failing and the call isn't getting executed at all. If I put in a fakeembedly
plug-in, it works: http://jsbin.com/ucuru4/2I 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.
If the code is okay but you find that the
embedly
call is failing intermittently, may be best to wrap it in atry/catch
block.