1

每当您单击标题链接时,我都会收到 JavaScript 错误;从本质上讲,这document.write('<a href="javascript:myclick(' + (i) + ')">' + '[[Title]]' + '<\/a><br>'); 句话让我很沮丧,因为除了 IE7/8 之外的所有其他浏览器都没有任何问题。然而,我们的大多数访问者都在使用 IE7/8。该问题仅发生在 IE 中,几乎没有其他问题,但是据我所知,当我调试它时,它是一个 javascript 错误。

Thanks..

这是信息:

IE8 调试:

Line: 1 
Error: Function expected 

myclick(3) 
Function expected JScript - window script block, line 1 character 1 

IE9 调试(在 IE8 模式下):

myclick(7)
SCRIPT5007: The value of the property 'myclick' is null or undefined, not a Function object script block (4), line 1 character 1

这是第 1 行:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><meta http-equiv="X-UA-Compatible" content="IE=edge" >

这是完整的脚本代码;谷歌地图:

<script type="text/javascript">
  var MapCenter = new google.maps.LatLng(41.52369114627216,-90.57780953284453)
  var i = -1;
  var Lat=new Array();
  var Long=new Array();
  var MarkerTitle=new Array();
  var Display=new Array();
  var myclick = new Array();
  var gmarkers = new Array();
</script>

<script type="text/javascript">
  var i = i + 1;
  Lat[i] = [[Lat]];
  Long[i] = [[Long]];
  MarkerTitle[i] = '[[Title]]';
  Display[i] = '<table><tr><td><div style="color: #a41d21;font-size: 13px; font-weight: bold;">[[Title]]</div></td></tr><tr><td>[[Address]]<br />[[City]], [[State]] [[Zip]]</td></tr><tr><td>[[Phone]]</td></tr><tr><td><a href="mailto:[[Email]]">[[Email]]</a></td></tr><tr><td><a href="[[WebURL]]" target="_blank">[[WebURL]]</a></td></tr></table>';
</script>

<div id="LeftArea" style="width: 220px; float: left; border-bottom: 1px solid #dedede; padding: 5px 0 5px 0;">
  <div style="color: #a41d21;font-size: 13px; font-weight: bold;">
    <script type="text/javascript">
      document.write('<a href="javascript:myclick(' + (i) + ')">' + '[[Title]]' + '<\/a><br>');
    </script>
  </div>
  <div>
    [[Address]]<br />
    [[City]], [[State]] [[Zip]]
  </div>
</div>

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  function initialize() {
    myclick = function myclick(i) {
      google.maps.event.trigger(gmarkers[i], "click");
    }

    var myOptions = {
      zoom: 12,
      center: MapCenter,
      zoomControl: true,
      zoomControlOptions: {
        position: google.maps.ControlPosition.TOP_RIGHT,
        style: google.maps.ZoomControlStyle.SMALL
      },
      mapTypeControl: true,
      mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
      },
      scaleControl: true,
      scaleControlOptions: {
        position: google.maps.ControlPosition.TOP_CENTER
      },
      mapTypeId: google.maps.MapTypeId.ROADMAP,
    };

    var map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);

    for (var i = 0, length = 50; i < length; i++) {
      var latLng = new google.maps.LatLng(Lat[i],Long[i]); 
      var InfoWindow = new google.maps.InfoWindow();

      var marker = new google.maps.Marker({
        position: latLng,
        map: map,
        title: MarkerTitle[i],
        html: Display[i]
      });

      gmarkers[i] = marker;

      google.maps.event.addListener(marker, 'click', function () {
        InfoWindow.setContent(this.html);
        InfoWindow.open(map, this);
      });
    }

    google.maps.event.addListener(map, 'click', function() {
      InfoWindow.close();
    });
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>
4

2 回答 2

1

我认为您不需要在此变量定义中包含函数名称:

myclick = new function(i) {
      google.maps.event.trigger(gmarkers[i], "click");
}
于 2012-06-04T14:46:03.587 回答
0

代替

<script type="text/javascript">
document.write('<a href="javascript:myclick(' + (i) + ')">' + '[[Title]]' + '<\/a><br>');
</script>

通过以下

<script type="text/javascript">
document.write('#' <a href="#" onclick="javascript:myclick(' + (i) + ')">'> + '[[Title]]' + '<\/a><br>');
</script>
于 2015-12-05T17:19:59.353 回答