尝试在模态表单上实现自动增量功能,并在Goggle地图上添加文本输入。
问题在于我的文本字段将所有值的总和相加,因此当我的字段以值='0'开头时,我得到以下递增的值:1,3,6,10,15,21 ,28,... 我只想简单地增加1:1,2,3,4,5,...
这是我的代码的样子:
模态表单上的HTML输入
<input type="text" class="form-control" id="num" value='0'>
JS的一部分显示Google Maps Api v3
//Add listener to map, to insert new Marker with modal
google.maps.event.addListener(map, "dblclick", function(event){
marker = new MarkerWithLabel ({
position: event.latLng,
map: map,
icon:mmcross,
draggable: true,
labelContent: '',
labelAnchor: new google.maps.Point(15,33),
labelClass: "labels", // the CSS class for the label
labelInBackground: false
});
map.setCenter(event.latLng);
//Open Modal Form to insert data
google.maps.event.addListener(marker, 'click', function() {
$('#myModal').modal('show');
$('#myModal').on('shown.bs.modal', function() {
$("#num").get(0).value++
});
});
});
答案 0 :(得分:0)
好的,我必须删除第二个$('#myModal')调用以使其正常工作:
google.maps.event.addListener(marker, 'click', function() {
$('#myModal').modal('show');
$(function() {
$("#num").get(0).value++
});
});