[英]show Latitude and Longitude marker values in iFrame
I have a main HTML file (index.html) where i load a Map (OpenLayers) and each time a user click somewhere on the Map a marker is added and a Modal window will open with an iframe inside (iframe_content.html).我有一个主 HTML 文件 (index.html),我在其中加载地图 (OpenLayers),每次用户单击地图上的某个位置时,都会添加一个标记,并且会打开一个带有 iframe (iframe_content.html) 的模态窗口。 This iframe content file has a Form with many input fields and i want to show the Latitude and Longitude marker values in the correspondent input field.
这个 iframe 内容文件有一个包含许多输入字段的表单,我想在对应的输入字段中显示纬度和经度标记值。
I'm a JavaScript noob but at the moment i already can grab those LonLat values and show them on a JS alert, so i guess i only need to figure it out how to "send" these values to the correspondent inputfield located in the other file «iframe_content.html».我是一个 JavaScript 菜鸟,但目前我已经可以获取那些 LonLat 值并在 JS 警报中显示它们,所以我想我只需要弄清楚如何将这些值“发送”到位于另一个的对应输入字段文件«iframe_content.html»。
Can you please give me some tips on this?你能给我一些关于这个的提示吗? Thanks in advance!
提前致谢!
NC数控
When you load the modal you could have something like this:当您加载模态时,您可能会遇到这样的事情:
var iframe = document.getElementById('iframe_id');
var inner = iframe.contentDocument || iframe.contentWindow.document;
Now if you have the fields as a name array:现在,如果您将字段作为名称数组:
var fields = inner.getElementsByName('fields[]');
Or get them by the id:或者通过 id 获取它们:
var lat_field = inner.getElementsById('latitude');
var lon_field = inner.getElementsById('longitude');
Now just set the value of the fields to the value you want in this case the coordinates:现在只需将字段的值设置为您想要的值,在这种情况下为坐标:
fields[0].value = coordinate['latitude'];
fields[1].value = coordinate['longitude'];
Or with the ids:或者使用 ID:
lat_field.value = coordinate['latitude'];
lon_field.value = coordinate['longitude'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.