[英]jQuery Doesn't work when product loaded via AJAX
jQuery is working fine when Open page. 打开页面时,jQuery工作正常。 but, jQuery Doesn't work when product loaded(change) via AJAX.
但是,当通过AJAX加载(更改)产品时,jQuery不起作用。 I have used jquery-1.7.1.min.js
我用过jquery-1.7.1.min.js
$(document).ready(function () {
$screensize = $(window).width();
if ($screensize > 1199) {
$('#content .product-grid > div:nth-child(3n)').after('<span class="clearfix visible-lg-block"></span>');
}
if ($screensize < 1199) {
$('#content .product-grid > div:nth-child(3n)').after('<span class="clearfix visible-lg-block visible-md-block"></span>');
}
if ($screensize < 991) {
$('#content .product-grid > div:nth-child(3n)').after('<span class="clearfix visible-lg-block visible-sm-block"></span>');
}
});
How can I fix it? 我该如何解决?
I have try following code. 我尝试下面的代码。 So, It is working.
因此,它正在工作。 but, sometime is not work.
但是,有时是行不通的。
$(document).on('ajaxComplete ready', function(){
// FUNCTION CODE
});
Make a method and call it when the DOM is loaded AND AJAX is done. 创建一个方法,并在加载DOM并完成AJAX后调用它。
$(document).ready(function(){
var resizeMe = function () {
$screensize = $(window).width();
... Do what you want here
};
$.ajax({...}).done( function () { resizeMe(); } );
resizeMe();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.