【问题标题】:change value of input from other page更改来自其他页面的输入值
【发布时间】:2013-04-23 15:57:46
【问题描述】:

在页面中有表单,并在从其他页面加载的 colorbox 中打开谷歌地图 我想在其他页面表单中移动地图中的拖动按钮时更改值

表单页面:form.php

    <form action="ajax-trades/submit-edit.php"  method="POST">
<div id="address"></div>
                <input type="hidden" name="target" id="target" value="<?php echo $row['gmap']; ?>">
<input type="submit" onclick="window.scrollTo(0, 200);" value="submit" class="button"  />

</form>

这是用于在其他页面加载谷歌地图的 jquery:

    <script type="text/javascript">
$(function(){
function objToString (obj) {
            var str = '';
            for (var p in obj) {
                if (obj.hasOwnProperty(p)) {
                    str += obj[p] + ',' ;
                }
            }
            return str;
}
$("#test").gmap3({
  marker:{
    latLng: [35.712926551232044, 51.40896647885131,],
    options:{
      draggable:true
    },
    events:{
      dragend: function(marker){
        var position = (marker.getPosition());
        //$("#map").html(position[2]);
        //var stingposition = objToString (position);
        $("#address").html('<input type="hidden" name="map" value="' + position.toString() + '" />');

        $(this).gmap3({
          getaddress:{
            latLng:marker.getPosition(),
            callback:function(results){
              var map = $(this).gmap3("get"),
                infowindow = $(this).gmap3({get:"infowindow"}),
                content = results && results[1] ? results && results[1].formatted_address : "no address";
              if (infowindow){
                infowindow.open(map, marker);
                infowindow.setContent(content);
              } else {
                $(this).gmap3({
                  infowindow:{
                    anchor:marker,
                    options:{content: content}
                  }
                });
              }
            }
          }
        });
      }    
    }
  },
  map:{
    options:{
      zoom: 14
    }
  }
});
});
</script> 

只有这一行重要工作但不工作!

        $("#address").html('<input type="hidden" name="map" value="' + position.toString() + '" />');

【问题讨论】:

  • 请定义“不工作”。你期望会发生什么?究竟会发生什么?
  • 我想打印到 from.php

标签: php jquery google-maps google-maps-api-3


【解决方案1】:

尝试使用这个:

$("#address", window.top.document).html('<input type="hidden" name="map" value="' + position.toString() + '" />');

window.top 表示您将在“根”页面上搜索 #address 元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    相关资源
    最近更新 更多