Fire javascript/jquery in jQuery dialog after .load
I have a jQuery dialog which I fire from a list of items in a jTemplate:
<a href="#" class="view-map" id="{$T.Address.AddressCity.Lat}|{$T.Address.AddressCity.Lon}"><img src="/images/iconography/tiny-map.png" width="16" height="16" alt="See this address on a map..." title="See this address on a map..."></img></a>
jQuery:
$('.view-map').live('click', function () {
$('#map')
.data('id', $(this).attr('id'))
.dialog('open')
;
return false;
});
$('#map').dialog({
autoOpen: false,
resizeable: false,
position: 'top',
modal: true,
width: 650,
open: function() {
v开发者_开发知识库ar location = $(this).data('id').split('|');
$(this).load('/components/google/map.aspx?lat=' + location[0] + '&lon=' + location[1]);
},
buttons: {
'Ok': function () {
$(this).dialog('close');
}
}
});
When the map.aspx
page loads, I want the following javascript to fire (so I can get the map from Google):
function initialize() {
var myOptions = {
zoom: 9,
disableDefaultUI: true,
center: new google.maps.LatLng(<%=Lat%>, <%=Lon%>),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('x-map-placeholder'), myOptions);
document.getElementById('x-map-loader').style.display = 'none';
}
function loadScript() {
alert("I'm away!");
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
document.body.appendChild(script);
}
function toLower(s) {
return s.toLowerCase();
}
function toFixed(n) {
return n.toFixed(0);
}
window.onload = loadScript;
Obviously it doesn't and I think this is because how the dialog is called - I understand that calling a dialog isn't window.onload
ing and therefore won't fire the loadScript
, but I'm not sure what to do to get it to fire....
Can anyone help? :)
Help is appreciated.
use
$(function(){
function to fire
});
精彩评论