Tag: 回调

这是一个有效的jquery回调函数调用吗?

我执行这样的函数, $(document).ready(function() { getEntities(“Clients/GetClients”, 0, formatClientsResult); var maxvalues = $(“#HfId”).val(); $(“.pager”).pagination(maxvalues, { callback: getEntities(“Clients/GetClients”, formatClientsResult), current_page: 0, items_per_page: 5, num_display_entries: 5, next_text: ‘Next’, prev_text: ‘Prev’, num_edge_entries: 1 }); }); $(function() { $.ajaxSetup({ contentType: ‘application/json; charset=utf-8’, global: false, async: false, dataType: ‘json’, beforeSend: function() { $(‘.loading’).show(); }, complete: function() { $(‘.loading’).hide(); } }); }); function getEntities(url, […]

Google Maps V3 setDirections()回调

执行setDirections()时是否有可能获得回调? <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places&language=”> $(document).ready(function(){ var destination = ”; var directionsDisplay = new google.maps.DirectionsRenderer({ draggable: true }); var directionsService = new google.maps.DirectionsService(); var geocoder; var infoWindowContent = ‘infocontent’; var map; var marker; var position = new google.maps.LatLng(46.80193957664, 11.41754150390625); function calcRoute(start, end) { var request = { origin: start, destination: end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, […]

如何在jQuery触发器上运行回调函数(“click”)?

我需要在trigger调用的回调中触发自定义事件,但我无法使其工作。 我试过这个: var $input = $( “.ui-popup-container” ).find( “input” ).eq(2); function runtests () { console.log(“clicked the input”); }; $input.trigger(‘click’, runtests()); 还有这个: var $input = $( “.ui-popup-container” ).find( “input” ).eq(2); $input.trigger(‘click’, function(){ console.log(“clicked the input”); } 两者都不奏效。 题: 当我触发元素点击时如何获得回调函数?

jQuery图像加载回调

在加载然后用户交互之后动态地将图像添加到页面,并且在该图像完全加载之后无法触发function。 我认为使用jQuery的.load()方法会很好..但根据我的控制台和一堆文档.log业务,它从未执行过。 见下文..谢谢! $(‘body’) .append(”) .load(function(){ console.log(‘ad load complete’); $(‘#submit’).click(); }); 更新: 为了澄清,这是在document和window加载之后。

加载多个图像时的回调跨浏览器解决方案?

我检查了其他问题,但是他们都有关于如何在加载一个特定图像时进行回调的信息: var img = new Image(); img.src = “images/img.png”; if (!img.complete) { img.onload = function() { // code to be executed when the image loads } } 或者,只需检查所有图像是否都加载了“if”语句。 此外,$(window).load(或onLoad或其他)不起作用。 在我的情况下,我正在加载两个图像: var img1 = new Image(); var img2 = new Image(); img1.src = ‘images/img1.png’; img2.src = ‘images/img2.png’; 如何定义类似于第一个示例中的回调,但是当两个图像完成加载时它会被执行? 感谢您的时间。

jQuery:动态图像处理(等待加载)

我正在尝试编写一个内置函数的插件,等待页面上的所有图像在执行之前加载。 $(window).load()只有在页面的初始加载时才有效,但如果有人想通过包含图像的AJAX下拉某些HTML,它就不起作用。 有没有什么好的方法来实现它并实现它,以便它可以在插件中自包含? 我已经尝试循环$(‘img’).complete ,我知道这不起作用(图像永远不会加载,浏览器崩溃,“脚本需要很长时间才能完成”bug)。 有关我正在尝试执行的操作的示例,请访问我要查找的插件页面: http://www.simplesli.de 如果您转到“更多用途”部分(在导航栏上单击它),您将看到图像幻灯片显示无法正确加载。 我知道当前的代码不起作用,但它只是保持不变,直到我弄明白了。 编辑:尝试此解决方案,但它只是不起作用: if($(‘.simpleSlide-slide img’).size() > 0) { var loaded_materials = $(‘.simpleSlide-slide img’).get(); } else { var loaded_materials = $(‘.simpleSlide-slide’).get(); } $(loaded_materials).live(‘load’, function() { /* Image processing and loading code */ });

如何将Object上下文传递给jQuery.ajax JSONP回调?

当ajax提供程序预定义其回调时,我遇到了将javascript对象上下文传递给JSONP ajax请求的回调处理程序的问题。 (Flickr是服务提供商)。 我将举一个简化的例子: function Person(anId){ this.name; this.id = anId; var self = this; this.loadName = function(){ $就({ url:“jsonp.json”, dataType:“jsonp”, jsonpCallback:“handleJSON”, data:{id:this.id}, 背景:自我, 成功:函数(数据){ self.name = data.name; } }); } } var handleJSON = function(data){ console.log(“已收到”+ data.name); } var a = new Person(234); a.loadName(); var b = new Person(345); b.loadName(); 上面的示例工作正常,控制台输出handleJSON函数的行。 但在这个函数中,我没有引用调用它的原始对象。 我希望调用成功函数:这里我可以引用自变量。 有几种可能的解决方案,但我没有任何运行。 我将截取jQuery为我生成的回​​调名称,并将其作为jsonpCallback参数中的值。 […]

在attr()回调中执行函数?

不确定我是否正确这样做。 这是我的.js : var currentIMG; $( ‘.leftMenuProductButton’ ).hover(function () { currentIMG = $(“#swapImg”).attr(“src”); var swapIMG = $(this).next(“.menuPopup”).attr(“id”); $(“#swapImg”).css(“opacity”, 0) .attr(“src”, productImages[swapIMG], function(){ $(“#swapImg”).fadeTo(“slow”, 1); }); }, function () { $(“#swapImg”).stop().attr(“src”,currentIMG); }); 我要做的是将IMG Opacity设置为0( #swapImg ),替换它的src ,然后将其淡入。所以我试图使用.attr()的回调淡化它。 如果我这样做不正确,有人可以解释一个更好的方法吗? 我试图在回调中这样做的原因是我需要fadeTo只在新图像完全加载后才出现,否则它会闪现一点点。 我正在使用jQuery 1.4,根据http://jquery14.com/day-01/jquery-14 ,你可以在.attr()方法中进行回调。

如何等待一个jquery动画在下一个开始之前完成?

我有以下jQuery: $(“#div1”).animate({ width: ‘160’ }, 200).animate({ width: ‘toggle’ }, 300 ); $(“#div2”).animate({ width: ‘toggle’ }, 300).animate({ width: ‘150’ }, 200); 我的问题是两者都发生在同一时间。 我想在第一个完成时启动div2动画。 我尝试了下面的方法,但它做了同样的事情: $(“#div1”).animate({ width: ‘160’ }, 200).animate({ width: ‘toggle’ }, 300, ShowDiv() ); …. function ShowDiv(){ $(“#div2”).animate({ width: ‘toggle’ }, 300).animate({ width: ‘150’ }, 200); } 如何让它等待第一个完成?

使用JavaScript自定义确认对话框

我想创建一个类似于confirm()的JavaScript函数,它显示一个对话框(带有问题和2个按钮的div),如果用户单击“确定”则返回true否则返回false 。 是否可以使用JavaScript / jQuery但没有插件(例如jQuery UI或Dialog)? 因为我正在努力减少尺寸和往返时间…… 我试着编写这段代码,但我不知道如何让用户点击这个函数“等待”。 我想以这种方式使用我的函数: answer=myConfirm(“Are you sure?”) 通过这种方式,我可以在几个上下文中使用相同的函数,只需更改作为参数传递的问题。 这与confirm()的行为相同