< ul>时调用jquery函数内容改变 [英] Call jquery function when <ul> content change
问题描述
以下是我的代码
JS
jQuery(document).ready(function($){
$('。ProductList' ).live('change',function(){
alert('content is now now');
});
});
HTML
< ul class ='ProductList List Clear'>当内容改变时,
调用jquery函数。
< li>< / li>
< li>< / li>
< li>< / li>
< / ul>
建议我一些想法,以便我可以解决它。
我尝试基于内容更改调用函数,因为我工作在bigcoomerce定制和大商业不允许我访问ajax函数,因为有限的访问,所以我需要调用这样的函数。
测试:{如果特定的ajax请求被设置为全局false,这将不起作用}
! function(){
var ulContent;
$(document).ajaxStop(function(){
var $ ul = $('。ProductList');
if(ulContent!== $ ul.html()){
ulContent = $ ul.html();
$ ul.trigger('contentChanged');
}
});
}(); ('contentChanged',callback);
$('。ProductList')。
回调函数是您在UL内容更改时要调用的函数。您应该直接从ajaxStop处理程序调用它,但通常我们使用自定义事件。
或者如果您不知道以前的语法是什么意思,请使用它:
$('contentChanged',function(){alert('UL content changed !!!'); });
I try to call jQuery function when ul content is changed.
Below is my code
JS
jQuery(document).ready(function($) {
$('.ProductList').live('change', function() {
alert('content is changed now');
});
});
HTML
<ul class='ProductList List Clear'>
call jquery function when content change here.
<li></li>
<li></li>
<li></li>
</ul>
Suggest me some idea so I can solve it.
I am try to call function based on content change because I work on bigcoomerce customization and big commerce not allow me to access ajax function because of the limited access so I need to call function like that.
Test that: {this won't work if specific ajax request is set to global false}
! function () {
var ulContent;
$(document).ajaxStop(function () {
var $ul = $('.ProductList');
if(ulContent !== $ul.html()){
ulContent = $ul.html();
$ul.trigger('contentChanged');
}
});
}();
$('.ProductList').on('contentChanged',callback);
callback is the function you want to call when content of UL changed. You should just call it directly from ajaxStop handler but usually we use a custom event.
Or use that if you don't know what previous syntax means:
$('.ProductList').on('contentChanged',function(){alert('UL content changed!!!');});
这篇关于< ul>时调用jquery函数内容改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!