我如何结合这些功能。基本上,当单击复选框时,会发生某些事情,如果页面加载,并且已经单击了复选框,则会发生与第二个函数相同的事情。
$(document).on("click", ".dimensions", function() {
var size = $('.td-hide');
if ($('input#dimensions').is(':checked')) {
size.show();
$('.single-select-sm').css('width','148px')
} else {
size.hide();
$('.single-select-sm').css('width','230px')
}
});
$(function() {
var size = $('.td-hide');
if ($('input#dimensions').is(':checked')) {
size.show();
$('.single-select-sm').css('width','148px')
} else {
size.hide();
$('.single-select-sm').css('width','230px')
}
});
答案 0 :(得分:1)
var myFunc = function()
{
var size = $('.td-hide');
if ($('input#dimensions').is(':checked')) {
size.show();
$('.single-select-sm').css('width','148px')
} else {
size.hide();
$('.single-select-sm').css('width','230px')
}
}
$(document).on("click", ".dimensions", function() {
myFunc();
}
$(function() {
myFunc();
}