Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在谷歌地图标注框中显示星星?_Javascript_Google Maps - Fatal编程技术网

Javascript 如何在谷歌地图标注框中显示星星?

Javascript 如何在谷歌地图标注框中显示星星?,javascript,google-maps,Javascript,Google Maps,预期值:请参见谷歌地图标注框中的1-5颗星 Actual:页面闪烁,页面顶部仅显示一长串星星 我怀疑我不应该使用文档。写 <html> <head> <script type="text/javascript"> //some Google Maps API code function showstar(x) { var i = 0; while (i < x)

预期值:请参见谷歌地图标注框中的1-5颗星
Actual:页面闪烁,页面顶部仅显示一长串星星

我怀疑我不应该使用文档。写

<html>
    <head>

    <script type="text/javascript">

    //some Google Maps API code

         function showstar(x)
       {
        var i = 0;
        while (i < x)
        {
         document.write("<img src=\"img/star.gif\" width=\"15\" height=\"15\" />");
         i++;
        }
       }

       var html = "Review stars: " showstar(star)

       GEvent.addListener(marker, 'click', function() {
          marker.openInfoWindowHtml(html);
          });
          return marker;
        }

      </script>
    </head>

      <body onload="load()" onunload="GUnload()">
        <div id="map" style="width: 700px; height: 500px"></div>
      </body>

    </html>

//一些谷歌地图API代码
函数showstar(x)
{
var i=0;
而(i
正确,您不应该使用document.write这样写-在页面加载完成之前执行

在函数末尾返回HTML字符串,而不是document.write:

function showstar(x) {
    var i = 0, starsHTML = "";
    while (i < x) {
        starsHTML += "<img src=\"img/star.gif\" width=\"15\" height=\"15\" />";
        i++;
    }
    return starsHTML;
}
函数showstar(x){
var i=0,starsHTML=“”;
而(i
PS我假设
star
在使用之前的某个地方定义并分配了一个值,您在本文的代码中没有提供该值