在document.ready上触发jQuery函数
我在.change()函数中有一点Javascript,希望在.ready()函数中应用相同的代码。有没有什么方法可以实现这一点,而不需要将代码复制粘贴到函数中在document.ready上触发jQuery函数,jquery,Jquery,我在.change()函数中有一点Javascript,希望在.ready()函数中应用相同的代码。有没有什么方法可以实现这一点,而不需要将代码复制粘贴到函数中 $('.selabw').change(function(){ let that = $(this); let value = that.parent().next().prev().find('select').val(); console.log('"' + value + '"'); i
$('.selabw').change(function(){
let that = $(this);
let value = that.parent().next().prev().find('select').val();
console.log('"' + value + '"');
if(value == ''){
that.parent().next().find('input').removeClass('disabledBetrag').removeAttr('disabled');
} else {
that.parent().next().find('input').val('0,00');
that.parent().next().find('input').attr('disabled', 'true').addClass('disabledBetrag');
}
});
$(document).ready( function(){
// trigger $('.selabw').change(function(){}); ?
}
你可以这样试试
$('.selabw').trigger('change')
请参阅此stackoverflow链接,很抱歉回复太晚。非常感谢你的回答。正是我需要的!