Home > Web Front-end > JS Tutorial > body text

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

小云云
Release: 2018-01-12 10:37:02
Original
1803 people have browsed it

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>
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!