除非我使用alert(),否则JavaScript无法正常工作!

编程入门 行业动态 更新时间:2024-10-13 02:18:21
本文介绍了除非我使用alert(),否则JavaScript无法正常工作!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不时遇到这个问题,但我不知道如何解决.这是我失败的代码:

I run into this issue from time to time and I don't know how to solve it. Here's my code that fails:

function on_lightbox_open() { system.contextBrowserInit(); updateUrl(year + '/' + month + '/' + id); ads.reload(); system.analytics.reload(); FB.XFBML.parse($('#bottom_flap .fb_like').get(0)); // facebook $.ajax({ url: 'platform.twitter/widgets.js', dataType: 'script', cache: true }); $('#lightbox .close').live('click', function(){ $.modal.close(); }); }

如果我像这样一开始就添加了警报:

If I add an alert at the begining like so:

function on_lightbox_open() { alert('i work now'); system.contextBrowserInit(); updateUrl(year + '/' + month + '/' + id); ads.reload(); system.analytics.reload(); FB.XFBML.parse($('#bottom_flap .fb_like').get(0)); // facebook $.ajax({ url: 'platform.twitter/widgets.js', dataType: 'script', cache: true }); $('#lightbox .close').live('click', function(){ $.modal.close(); }); }

它神奇地起作用.如何使其在没有烦人的随机警报的情况下工作?

It magically works. How to make it work without an annoying random alert?

推荐答案

也许您对.live()的使用需要完全加载的文档,而警报只会使浏览器多花一些时间.尝试使用$(document).ready();

Perhaps your use of .live() requires a fully loaded document and the alert just buys the browser some extra time. Try surrounding with $(document).ready();

来源: jQuery驱动的应用程序.没有alert()将无法工作

更多推荐

除非我使用alert(),否则JavaScript无法正常工作!

本文发布于:2023-11-27 19:57:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   非我   工作   JavaScript   alert

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!