gpt4 book ai didi

jQuery - 运行change()和ready()函数

转载 作者:行者123 更新时间:2023-12-03 22:08:22 25 4
gpt4 key购买 nike

我有一个在 .change() 上运行的 jquery 代码。但我想在 jquery .ready() 上运行相同的代码,但它不起作用。

这是我的代码:

    jQuery('.nhp-opts-select-hide-below').change(function(){
var option = jQuery('option:selected', this);
if(option.data('show').length > 0 || option.data('hide').length > 0){
jQuery(option.data('show')).each(function(){
if(jQuery(this).closest('tr').is(':hidden')){
jQuery(this).closest('tr').fadeIn('fast');
}
});
jQuery(option.data('hide')).each(function(){
if(jQuery(this).closest('tr').is(':visible')){
jQuery(this).closest('tr').fadeOut('fast');
}
});

}else{
jQuery(option.data('show')).each(function(){
if(jQuery(this).closest('tr').is(':visible')){
jQuery(this).closest('tr').fadeOut('fast');
}
});
jQuery(option.data('hide')).each(function(){
if(jQuery(this).closest('tr').is(':hidden')){
jQuery(this).closest('tr').fadeIn('fast');
}
});
}
});

请告诉我如何在 jquery 上运行上面的代码?

最佳答案

只需调用 .change()没有争论。将整个内容放入准备好的处理程序中,然后:

jQuery(function($) {
$('.nhp-opts-select-hide-below').change(function(){
// snip...
}).change(); // that's it
});

关于jQuery - 运行change()和ready()函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17247279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com