当我们单击无线按钮时,它会运行一个onchange jQuery函数。但是,如果我们通过一个链接参数直接检查这个单选按钮,函数就不会被调用。拜托,怎么解决这个问题?我尝试过将onchange更改为onclick,但没有成功。
我正在处理的页面:一旦手动选择了任何Store,onchange函数将隐藏Store并显示分类DIV,模拟一个步骤筛选器。http://www.hotsales.com.br/procurar/
这是自动选择某些Store的直接链接参数。但是这样,onchange函数就不会运行,所以Store仍然是可见的,类别DIV仍然是隐藏的。store=852
这是在选择Store (手动或直接链接)时应该运行的第一个函数。
/* AJAX SEARCH*/
$(document).on( 'change', '.advanced-search input', function(){
start_ajax_search3();
$.ajax({
url: $('.advanced-search').attr('action'),
data: $('.advanced-search').serialize(),
success: function( response ){
handle_ajax_search_response( response ); /*this function hide/show desired DIV*/
},
complete: function(){
end_ajax_search();
}
});
});这就是DIVs是如何隐藏/显示的:
function handle_ajax_search_response( response ){
var $response = $('<div>'+response+'</div>');
$('.ajax-results').html( $response.find('.ajax-results').html() );
$('.ajax-sidebar').html( $response.find('.ajax-sidebar').html() );
$('.category-filter').show();
$('.store-filter').hide();
$('.offer-type-filter').show();}发布于 2017-03-30 15:09:24
您可以在change和document ready上调用您的函数,例如:
function test(chk){
console.log("called by" + $(chk).attr("id"));
}
$(document).ready(function(){
if($("#chkTest2").is(":checked")){
test($("#chkTest2"));
}
});
$(".chkboxes").on( 'change', function(){
test(this);
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="chkboxes" type="checkbox" id="chkTest1">Test 1
<input class="chkboxes" type="checkbox" id="chkTest2" checked="checked"> Test 2
希望它能帮到你,再见。
https://stackoverflow.com/questions/43121470
复制相似问题