Tag: 回调

无限滚动与Magnific Popup回调

我正在使用Infinite滚动和Magnific Popup。 弹出窗口对“第1页”的内容起作用,但之后失败。 我试图在infiniteScroll调用中使用MagnificPopup的回调。 $grid.infiniteScroll({ path: ‘.pagination__next’, append: ‘.grid__item’, outlayer: msnry, status: ‘.page-load-status’, }, function( newElements ) { $(‘.open-pop’).magnificPopup({ type: ‘inline’, mainClass: ‘mfp-fade’, fixedContentPos: false, gallery: { enabled: true, navigateByImgClick: false, } }); }); 我的问题类似于这个Magnific弹出窗口和无限滚动 ,我试图实现它是不成功的。 可能是一个额外的复杂因素是我正在使用砌体。 这是我的完整代码: // init Masonry var $grid = $(‘.grid’).masonry({ itemSelector: ‘none’, // select none at first columnWidth: ‘.grid__col-sizer’, gutter: […]

如何在$ .ajax的成功回调中传递$(this)

我已经看到了访问$(this)的几个不同的例子是ajax的成功回调但没有给我我想要的答案 – 他们都在ajax函数中访问$(this),我想将$(this)传递给a单独的function。 因此,如果有2个文本框需要validation $(“#tb1”).focusout(function(){ $.ajax({ type:’POST’, url: ‘validURL’, data: {various_parameters}, contentType: ‘application/json; charset=utf-8′, dataType:’json’, success: function(data){ validInput(data, $(this)); }, error: error }); } $(“#tb2”).focusout(function(){ $.ajax({ type:’POST’, url: ‘validURL’, data: {various_parameters}, contentType: ‘application/json; charset=utf-8′, dataType:’json’, success: function(data){ validInput(data, $(this)); }, error: error }); } function validInput(response, obj){ console.log(response.d); console.log(obj.val()); }; 当我运行代码时,我得到了响应的正确值。但是出现了错误:jquery-1.11.1.min.js:4未捕获的TypeError:无法读取obj.val()的undefined属性’toLowerCase’。 难道我做错了什么? 谢谢你的帮助。 请参阅:DOS /运行

如何将其他参数传递给回调并访问默认参数?

假设我将此作为jQuery小部件的选项: function oneFunc() { var myVar; //there is some widget calling $.widget(“ui.combobox”, $.ui.autocomplete, { options: { source: function (request, response){////doing something with myVar, request and response} } }); } 现在我想使用回调分离出function (request, response) 所以,我想要这样的东西: function oneFunc() { var myVar; //there is some widget calling $.widget(“ui.combobox”, $.ui.autocomplete, { options: { source: myCallBack }); } function myCallBack(request, response){ […]

需要按两次提交提交带有ajax的表单(jqueryvalidation插件)

在使用此插件提交之前,表单已经过validation。 并按代码中的说明提交: jQuery.validator.setDefaults({ submitHandler: function(){ jQuery(“form”).submit(function(e) { e.preventDefault(); jQuery.post(base_url + “blog/ajax_comment”, { author: jQuery(“#author”).val(), email: jQuery(“#email”).val(), url: jQuery(“#url”).val(), message: jQuery(“#message”).val() , post_ID: jQuery(“#post_ID”).val(), not: jQuery(“#not”).val() }, function (data) { //do stuff here }); }); } }); jQuery().ready(function() { // validate the comment form when it is submitted jQuery(“#commentform”).validate(); }); 要提交,我需要按两次提交按钮。 我是jQuery的新手,我不知道为什么会这样。 有没有一种简单的方法来解决这个问题?

为什么$ .each()比jquery中的循环慢?

有些消息来源要求在jquery中使用“for loop over $ .each()” ,因为$ .each()比ops / sec中的循环要慢 这是因为$ .each()的回调函数吗? 任何人都可以解释为什么$ .each()比jquery中的循环慢,在这种情况下我必须选择循环超过$ .each()或反之 ? 提前致谢。

jQuery插件回调

好吧,所以我要做的是一个插件,它返回一个jquery数组,用于回调函数。 让我们说我有这个代码“ (function($){ $.fn.extend({ //plugin name myPlugin : function(needed){ var defaults = { path : ‘action.php’, source : ” } var needed = $.extend(defaults,needed); //return return this.each(function(){ //it loads some pictures $(‘#selector’).load(needed.path,{‘src’:nedeed.source}) }); } }); })(jQuery的); 我想返回这些图片并在回调函数中访问它们。 这样的事情 $(‘#another_selector’).click(function(){ $(this).myPlugin({‘source’:’path/…etc’},function(){ $(‘img’).click(function(){ $(this).remove(); }); }); }); 谢谢

如何在表单的submit事件监听器中放置一个回调来等待用户对jquery即兴提示的响应?

这是我想做的 – 当用户单击主窗体的提交按钮时,显示提示(使用jquery的即兴)。 提示再次是一个具有密码字段和“确定”和“取消”按钮的表单。 当用户点击确定时,将发布主窗体(连同密码值,附加到主窗体)。 如果用户单击“取消”,则不会提交表单。 细节 我之前问了一个问题 – 在使用即兴function阻止正常提交后,jquery表单submit()在回调函数内部无效 并能够使用javascript的原生提示方法成功实现我想要的东西。 但我想用jquery的即兴插件做同样的事情。 这是使用本机javascript提示符的工作代码 – $(‘#frmAddAdnetworkTemplate’).submit(function(event){ promptText = “Password required”; postedPassword = prompt(promptText); if(postedPassword) { $(“form#frmAddAdnetworkTemplate”).find(“input#manage_adnetwork_password”).val(postedPassword); } else { event.preventDefault(); } }); 这是我到目前为止使用即兴的代码 – $(‘#frmAddAdnetworkTemplate’).submit(callBackSubmit); function callBackSubmit(event){ $.prompt(passwordForm,{ buttons: { Ok: true, Cancel: function(){event.preventDefault(); } }, submit: submitPasswordPrompt}); //how do I call event.preventDefault(); when user cancel’s. […]

如何覆盖JQuery的.show()和.hide()来触发事件之前和之后的事件?

我尝试覆盖JQuery的.show和.hide方法,以便在使用以下代码调用它们之前和之后启动触发器事件。 $(document).ready(function () { $(‘#dataBox’).bind(‘afterShow’, function () { alert(‘afterShow’); }); $(‘#dataBox’).bind(‘afterHide’, function () { alert(‘afterHide’); }); $(‘#dataBox’).bind(‘beforeShow’, function () { alert(‘beforeShow’); }); $(‘#dataBox’).bind(‘beforeHide’, function () { alert(‘beforeHide’); }); $(‘#toggleButton’).click(function(){ if($(‘#dataBox’).is(‘:visible’)) { $(‘#dataBox’).hide (); } else { $(‘#dataBox’).show(); } }); }); jQuery(function ($) { var _oldShow = $.fn.show; //Override jquery’s ‘show()’ method to include two triggered […]

如何在jquery中读取绑定的hover回调函数

我使用jquery为我页面上的元素设置hover回调。 我现在正在编写一个模块,需要暂时为某些元素设置新的hover行为。 新模块无法访问hoverfunction的原始代码。 我想在设置新的hover函数之前存储旧的hover函数,这样我就可以在完成临时hover行为时恢复它们。 我认为这些可以使用jquery.data()函数存储: //save old hover behavior (somehow) $(‘#foo’).data(‘oldhoverin’,???) $(‘#foo’).data(‘oldhoverout’,???); //set new hover behavior $(‘#foo’).hover(newhoverin,newhoverout); 做新的hover行为…… //restore old hover behavior $(‘#foo’).hover($(‘#foo’).data(‘oldhoverin’),$(‘#foo’).data(‘oldhoverout’)); 但是如何从jquery获取当前注册的hover函数? Shadow2531,我试图这样做而不修改最初注册回调的代码。 否则你的建议会正常工作。 感谢您的建议,并帮助澄清我正在寻找的内容。 也许我必须进入jquery的源代码并弄清楚这些回调是如何在内部存储的。 也许我应该将问题改为“是否可以在不修改jquery的情况下执行此操作?”

JQuery UI对话框显示等待消息,直到处理ajax调用

我认为一切都在标题中。 当我开始这个时,我认为这将是一个5分钟的代码或谷歌搜索时的快速结果…但现在是三个小时我在这: 只需显示一个对话框,其中包含“Please Wait …”消息,而我正在执行ajax调用以检索一些json结果,然后显示“结果完成”。 $(‘#switchOff’).live(“click”,function(){ $(‘#dialog’).dialog({ modal:true, open: function(){ // I would like to call myAjax function //From here ? // While my dialog is showing the Wait message… }, complete: function(){ //close the dialog when fished $(‘#dialog’).dialog(‘close’); }, }); }); function ajaxCall() { //my ajax call }