[英]Passing data-id to bootstrap modal and use it iframe url
我正在嘗試在Bootstrap Modal中顯示地圖。 我有包含位置鏈接的記錄列表。 單擊位置后,它將在模式窗口中顯示地圖位置。 我成功地將值傳遞給模態窗口。 但無法在iframe src鏈接中使用。 下面是我的代碼。
<a href="#myMapModal" class="btn fblack" data-toggle="modal" data-id="<?=$row['lat']?>,<?=$row['lng']?>">Location on Map</a>
和我的jQuery
<script>
$('#myMapModal').on('show.bs.modal', function (e) {
var location = $(e.relatedTarget).attr('data-id');
$(this).find('#latlng').text(location);
});
</script>
我試圖將返回值放在url中
<iframe width="570" height="300" frameborder="0" style="border:0;" src="https://www.google.com/maps/embed/v1/place?q=#latlng&key=xxxxxxxxxxx"></iframe>
我給了q=#latlng
我可以使用<div id="latlng"></div>
進行打印
但我無法在URL中使用。
使用此腳本,詳細了解Google API
<script>
$(function(){
$('#myMapModal').$('.bs-example-modal-lg').on('show.bs.modal', function (e) {
var location = $(e.relatedTarget).attr('data-id');
var newUrl = 'https://www.google.com/maps/embed/v1/view?key=1234¢er='+location;
console.log(newUrl);
$(this).find('iframe').attr('src',newUrl);
});
});
</script>
我做了什么使它工作。
<script>
$('#myMapModal').on('show.bs.modal', function (e) {
var location = $(e.relatedTarget).attr('data-id');
$.ajax({
type : 'post',
url : 'map-list.php', //Here you will fetch records
data : 'rowid='+ location, //Pass $id
success : function(data){
$('#fetched-data').html(data);//Show fetched data from database
}
});
});
</script>
在map-list.php上
<?php
//Include database connection
if($_POST['rowid']) {
$eveid = $_POST['rowid']; //escape string
?>
<iframe width="570" height="300" frameborder="0" style="border:0;" src="https://www.google.com/maps/embed/v1/place?q=<?=$eveid?>&key=AIzaSyCoqMKgHRLWPQAwjGq0dzRhSg6e4UlrgE4"></iframe>
<?
}
?>
在情態的身體
<div id="fetched-data"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.