大佬教程收集整理的这篇文章主要介绍了jquery – .live()或.livequery(),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我搜索了大约4天,发现我的问题是更改DOM的AJAX请求,并且由于脚本在此之前被加载,因此在ajax调用之后它不会运行.
如果我是对的,我需要解决这个问题? .live()或.livequery()插件?
我正在使用的所有JS都是这样的:
var $dd = $('.projects dl').find('dd'),$defBox = $('#def-Box'); $defBox.hide(); $('.projects').hover(function(){ $defBox.stop(true,truE) .fadeToggle(1000) .html('<p>Hover The links to see a description</p>'); }); $dd.hide(); $('.projects dl dt').hover(function(){ var $data = $(this).next('dd').html(); $defBox.html($data); }); // Ajax stuff // check for hash value in URL var hash = window.LOCATIOn.hash.substr(1); // check to ensure that a link with href == hash is on the page if ($('a[href="' + hash + '"]').length) { // Load the page. var toLoad = hash + '.PHP #main-content'; $('#main-content').load(toLoad); } $("nav ul li a").click(function(){ var goingTo = $(this).attr('href'); goingTo = goingTo.subString(goingTo.lasTindexOf('/') + 1); if (window.LOCATIOn.hash.subString(1) === goingTo) return false; var toLoad = $(this).attr('href')+' #main-content',$content = $('#main-content'),$loadimg = $('#load'); $content.fadeOut('fast',loadContent); $loadimg.remove(); $content.append('<span id="load"></span>'); $loadimg.fadeIn('slow'); window.LOCATIOn.hash = goingTo; function loadContent() { $content.load(toLoad,'',shownewContent) } function shownewContent() { $content.fadeIn('fast',hideLoader); } function hideLoader() { $loadimg.fadeOut('fast'); } return false; });
$('#main-content').load(toLoad,function() { $("#foo").Tinyscrollbar(); $("#bar").faceBox(); // etc });
对于事件处理程序,您可以在回调中重新绑定它们,如上例所示,或者使用.live或.delegate(您似乎已经使用过)以确保绑定在将来(ajax替换)元素中保留,例如:
$('.projects dl').delegate("dt","hover",function() { ... },function() { ... });
要么:
$('.projects dl dt').live("hover",function() { ... });
以上是大佬教程为你收集整理的jquery – .live()或.livequery()全部内容,希望文章能够帮你解决jquery – .live()或.livequery()所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。