Tuesday 15 February 2011

javascript - Execute a script once on page load -


I was messing about some code, but I struggled to achieve what I wanted I am For example, I have a map that displays when my areas are coordinated:

  // normal map display function map display () {var Latval = $ ('#lat'). Val (), lngval = $ ('# lng'). Val (); If ($ .trim (latval)! = '' & Amp; $ .trim (lngval)! = '') {Var map option = {zoom: 8, center: new google.maps.LatLng (Lollivell, Langela) MapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true, scrollable: wrong, dragable: incorrect}; Var map = new google.maps.Map (document.getElementById ('map_canvas'), map options); $ ('# Map_canvas') removeClass ('hidden'). } And {$ ('# map_canvas'). AddClass ('hidden'); }}   

I want to execute once per page, so if the value is in the field when the page loads, the map is displayed, but if the values ​​are removed the page load Or after the change, the map will not change because it only reads the variable at the beginning of the Throw page load.

Can anyone show me on my JSWeb How can this be displayed?

You are not calling the function mapDisplay (); mapDisplay

  jQuery (function ($) {mapDisplay ();})   

Demo:

No comments:

Post a Comment