ie8 支持 function.bind () 方法
<script type = "text/javaScript"> if (! function.prototype.bind) {function.prototype.bind = function (othis) {if (typeof this! == "function") {throw typeerror ("function.prototype.bind - ما يحاول أن يكون ملزمًا") ؛ } var aargs = array.prototype.slice.call (الوسيطات ، 1) ، ftobind = this ، fnop = function () {} ، fbound = function () {return ftobind.apply (this extualof fnop && othis؟ } ؛ fnop.prototype = this.prototype ؛ fbound.prototype = new fnop () ؛ إرجاع fbound. } ؛ } </script>主要解决 "百度地图" bug , 摘取如下代码 :
<! doctype html> <html> <head> <meta http-equiv = "content-type" content = "text /html ؛ charset = utf-8" /> <meta name = "powport" content = "inial-scale = 1.0 ، user-scalable = no" / 100 ٪ ؛ الهامش: 0 ؛ font-family: "微软雅黑" ؛} #AllMap {Width: 100 ٪ ؛ الارتفاع: 500px ؛} p {margin-left: 5px ؛ font-size: 14px ؛} </style> <script type = "text/javaScript" src = "http://api.map.baidu.com/api؟v=2.0&ak=39b92e64ae562663ceCECCD8AB8EB1 src = "http://libs.baidu.com/jquery/1.9.0/jquery.js"> </script> <title> 给多个点添加信息窗口 </itlem> <script type = "text/javaScrip typeerror ("function.prototype.bind - ما يحاول أن يكون ملزمًا غير قابل للاتصال") ؛ } var aargs = array.prototype.slice.call (الوسيطات ، 1) ، ftobind = this ، fnop = function () {} ، fbound = function () {return ftobind.apply (this extualof fnop && othis؟ } ؛ fnop.prototype = this.prototype ؛ fbound.prototype = new fnop () ؛ إرجاع fbound. } ؛ } </script> </head> <body> <div id = "allmap"> </viv> <p> 点击标注点 , 可查看由纯文本构成的简单型信息窗口 </p> </p body> </html> <script type = "text/javaScript"> // 百度地图 api 功能 map = new bmap.map ("allmap") ؛ Map.Centerandzoom (New Bmap.Point (116.417854،39.921988) ، 15) ؛ var data_info = [[116.417854،39.921988 ، ": : 北京市东城区王府井大街 88 号乐天银泰百货八层"] ، [116.406605،39.921585 ، "地址 : :"] ، [116.41222،39.912345 ، "地址 : 5 : 5 : 5 : 5 :"] var opts = {width: 250 ، // 信息窗口宽度 الارتفاع: 80 ، // 信息窗口高度 العنوان: "信息窗口" ، // 信息窗口标题 enableMessage: true // 设置允许信息窗发送短息} ؛ لـ (var i = 0 ؛ i <data_info.length ؛ i ++) {var marker = new bmap.marker (new bmap.point (data_info [i] [0] ، data_info [i] [1])) ؛ // 创建标注 var content = data_info [i] [2] ؛ map.addoverlay (علامة) ؛ // 将标注添加到地图中 marker.addeventListener ("Click" ، OpenInfo.bind (null ، content)) ؛ } وظيفة openInfo (المحتوى ، e) {var p = e.target ؛ var point = new bmap.point (p.getPosition (). lng ، p.getPosition (). lat) ؛ var infoWindow = new bmap.infowindow (content ، opts) ؛ // 创建信息窗口对象 map.openinfowindow (InfoWindow ، point) ؛ // 开启信息窗口} </script>