Home >Web Front-end >JS Tutorial >Tutorial on how jQuery can automatically execute an event after the HTML document is loaded
This article mainly introduces jQuery's method of automatically executing an event after the HTML document is loaded. It analyzes the related operating skills of the document's ready() event in the form of examples to automatically load and execute the event. Friends who need it can refer to it. Hope it helps everyone.
Originalonchange="fucntionname(parms)";
##
<select name="country" id="selCountries_{$sn}" onchange="region.changed(this, 1, 'selProvinces_{$sn}')" style="border:1px solid #ccc;"> <option value="0">{$lang.please_select}{$name_of_region[0]}</option> <!-- {foreach from=$country_list item=country} --> <option value="{$country.region_id}" {if $consignee.country eq $country.region_id}selected{/if}>{$country.region_name}</option> <!-- {/foreach} --> </select>Now in
document’s ready() eventThe onchange event is automatically executed inside.
<script type="text/javascript"> $(document).ready(function(){ var onll=document.getElementsById('selCountries_0'); region.changed(onll, 1, 'selProvinces_0'); }) </script>Look, now it is equivalent to automatically clicking and selecting "China" as soon as the document is loaded; Related recommendations:
Jquery’s basic object conversion and document loading usage examples_jquery
JS implements code execution after document loading is completed_javascript skills
Three methods for automatic execution (loading) of JS functions
The above is the detailed content of Tutorial on how jQuery can automatically execute an event after the HTML document is loaded. For more information, please follow other related articles on the PHP Chinese website!