如何使回声在内部工作';内容';jquery,在谷歌地图信息窗口中


How to make echo work inside 'content' of jquery,in google maps infowindow

我有一个新问题,我想在信息窗口的内容中回显php中的变量,有什么建议吗?

这是我的代码,在信息窗口内容中,我使用了一些html代码,我必须用php变量替换这些代码。例如:应该将deviceid1替换为数据库中的值

  var trieste = new google.maps.LatLng(45.6111555,13.8022614);
  var mapOptions = {
    zoom:      12,
    center:    trieste,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map($("#map_canvas")[0], mapOptions);
  var places =
    [
      {
        "position": [45.6466883,13.7631226]
      },
      {
        "position": [45.6433281,13.7895584]
      },
      {
        "position": [45.6017884,13.6673355] 
      },
      {
        "position": [45.622442,13.7641525] 
      }
    ]
  var currentPlace = null;
  var icons=["green.png","red.png","blue.png","yellow.png"];
  var i=0;
    $(places).each(function() {
      var place = this;
      var marker = new google.maps.Marker({
        position: new google.maps.LatLng(place.position[0], place.position[1],place.position[2],place.position[3]),
        map     : map,
        icon    : icons[i]
      });
   if(i==0)
   {
   var infowindow = new google.maps.InfoWindow({
   content: '<ul><li>Device ID1</li><li>Device configuration1</li><li>Device Description1</li></ul><a href="riacqua/activepanel.php">Goto RIACQUA</a>'
     }); 
   google.maps.event.addListener(marker, 'mouseover', function() {
   infowindow.open(map, marker);
     });
    google.maps.event.addListener(marker, 'mouseout', function() {
   infowindow.close();
     });
    }
content: '<ul><li><?=$deviceID?></li><li>Device configuration1</li><li>Device Description1</li></ul><a href="riacqua/activepanel.php">Goto RIACQUA</a>'

你只是想做一些类似thsi的事情吗?

var infowindow = new google.maps.InfoWindow({
   content: '<ul><li><?php echo $deviceId; ?></li><li>Device configuration1</li><li>Device Description1</li></ul><a href="riacqua/activepanel.php">Goto RIACQUA</a>'
     }); 

当然,如果你的设备id变量包含引号/单引号,那么你可能不得不去掉它们或转义它们。

这对php文件来说应该没有问题,但如果您试图在另一种文件类型(html、htm等)中进行渲染,则可能需要更改其他设置。