$('.sale_type').click(function() {}
I have such a function,if I click the radio,the function will execute,but how to trigger the click if the radio is checked when the page is loaded.
You can use jquery .trigger() when dom is ready:
$(":button").on("click", function() {
alert("Ok");
});
//here check if radio is checked
if ($(":radio").prop("checked"))
$(":button").trigger("click");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" checked />
<input type="button" value="test" />
References
Consider moving the code that gets triggered when the radio is clicked in to its own function. That way, you don't need to simulate/trigger events to execute the function:
$('.sale_type').on('click', function() {
doStuff();
});
$(document).on('ready', function() {
if($('.sale_type').is(':checked')) {
doStuff();
}
});
function doStuff() {
console.log('function code will be here');
}
You can use this way
Check your element when page load
$(document).read(function(){
var checkElementChecked = $('.sale_type').is(":checked");
if(checkElementChecked === true)
{
$('.sale_type').trigger('click');
}
});