本文介绍了jQuery驱动的应用程序.没有alert()将无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多关于jQuery的文章,但是没有涉及jQuery的文章,所以我去...我正在实现 http://javascript-array.com/scripts/jquery_simple_drop_down_menu/到现有应用程序中;但是,如果不将alert('msg ...')作为$(document).ready()调用中的第一个方法,就无法使其正常工作.

I have seen a lot of articles on this, but none dealing with jQuery, so here I go... I am implementing a version of a script from http://javascript-array.com/scripts/jquery_simple_drop_down_menu/ into an existing application; however, I cannot get it to work without adding alert('msg...') as the first method within the $(document).ready() call.

这似乎与加载时间无关……无论我等待多长时间,菜单都无法工作. setTimeout()也不起作用.但是,添加alert(),它就像一个魅力.我还可以通过Firebug正确执行绑定.

This does not seem to have anything to do with load time... no matter how long I wait, the menu does not work. setTimeout() does not work either. Add alert(), however, and it works like a charm. I can also properly execute the bindings via Firebug.

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

推荐答案

而不是使用 .bind() ,请使用 .live() ,以便将来处理所有元素实例.这应该可以解决ajax问题.

Instead of using .bind(), use .live() so that all future instances of the elements are taken care of. This should solve the ajax issue.

$(document).ready(function() {  
    $('#jsddm > li').live('mouseover', jsddm_open);
    $('#jsddm > li').live('mouseout',  jsddm_timer);
});

这篇关于jQuery驱动的应用程序.没有alert()将无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:00