2013-12-18 27 views
0

大家好,这里需要一点帮助。 我正在创建一个动态表单,并且在使用jquery获取HTML标签值方面遇到了一些麻烦。我拥有的是一张表格,里面是Google Map。每次Google地图更新时,它都是当前的经纬度,它当前的经纬度标签也在变化。我需要做的是获取当前的经纬度并将其显示在文本框中。改变的文本框的值也必须是动态的。如何在标签值发生变化时使用jquery事件?

在我的代码中,我有这个。

$(document).ready(function(){ 

    var current_latitude = $('#company_geo_lat').val(); //this is the textbox 
    var current_longitude = $('#company_geo_long').val(); //this is the textbox 

    var new_latitude = $('.new_latitude').html(); //this is the label 
    var new_longitude = $('.new_longitude').html(); //this si the label 

}); 

我应该怎么做才能动态替换文本框的值?我不想使用onchange事件,但我不知道。

回答

1

你可以使用http://api.jquery.com/change/

例如:

$('#company_geo_lat').change(function() { 
    $('.new_latitude').html($(this).val()); 
}); 

$('#company_geo_long').change(function() { 
    $('.new_longitude').html($(this).val()); 
}); 

除了JQuery的,你可以考虑AngularJS http://angularjs.org。在angularjs的首页有一些有用的例子。

1

我想对你最好的是添加事件

google.maps.event.addListener(map, "center_changed", function() { // map is your map var 
    var center = map.getCenter(); 
    $('.new_latitude').html(center.lat()); 
    $('.new_longitude').html(center.lng()); 
}); 

我希望我已经明白了你想要的目的。

+0

好的,我会尝试。 :) – Jerielle

相关问题