Home >Web Front-end >JS Tutorial >Tutorial on how jQuery can automatically execute an event after the HTML document is loaded

Tutorial on how jQuery can automatically execute an event after the HTML document is loaded

小云云
小云云Original
2018-01-12 10:37:021846browse

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, &#39;selProvinces_{$sn}&#39;)" 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(&#39;selCountries_0&#39;);
    region.changed(onll, 1, &#39;selProvinces_0&#39;);
  })
</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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn