讓ie8瀏覽器支持function.bind()方法
來(lái)源:易賢網(wǎng) 閱讀:1086 次 日期:2016-06-15 09:28:07
溫馨提示:易賢網(wǎng)小編為您整理了“讓ie8瀏覽器支持function.bind()方法”,方便廣大網(wǎng)友查閱!

ie8支持function.bind()方法

?123456789101112131415161718192021 <script type=text/javascript> if (!function.prototype.bind) { function.prototype.bind = function (othis) { if (typeof this !== function) { throw new typeerror(function.prototype.bind - what is trying to be bound is not callable); } var aargs = array.prototype.slice.call(arguments, 1), ftobind = this, fnop = function () {}, fbound = function () { return ftobind.apply(this instanceof fnop && othis ? this : othis, aargs.concat(array.prototype.slice.call(arguments))); }; fnop.prototype = this.prototype; fbound.prototype = new fnop(); return fbound; }; } </script>

主要解決“百度地圖”官網(wǎng)上的例子的bug,摘取如下代碼:

?12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 <!doctype html> <html> <head> <meta http-equiv=content-type content=text/html; charset=utf-8 /> <meta name=viewport content=initial-scale=1.0, user-scalable=no /> <style type=text/css> body, html {width: 100%;height: 100%;margin:0;font-family:微軟雅黑;} #allmap{width:100%;height:500px;} p{margin-left:5px; font-size:14px;} </style> <script type=text/javascript src=http://api.map.baidu.com/api?v=2.0&ak=39b92e64ae5622663ceceaccd8ab8eb1></script> <script src=http://libs.baidu.com/jquery/1.9.0/jquery.js></script> <title>給多個(gè)點(diǎn)添加信息窗口</title> <script type=text/javascript> if (!function.prototype.bind) { function.prototype.bind = function (othis) { if (typeof this !== function) { throw new typeerror(function.prototype.bind - what is trying to be bound is not callable); } var aargs = array.prototype.slice.call(arguments, 1), ftobind = this, fnop = function () {}, fbound = function () { return ftobind.apply(this instanceof fnop && othis ? this : othis, aargs.concat(array.prototype.slice.call(arguments))); }; fnop.prototype = this.prototype; fbound.prototype = new fnop(); return fbound; }; } </script> </head> <body> <div id=allmap></div> <p>點(diǎn)擊標(biāo)注點(diǎn),可查看由純文本構(gòu)成的簡(jiǎn)單型信息窗口</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,地址:北京市東城區(qū)王府井大街88號(hào)樂(lè)天銀泰百貨八層], [116.406605,39.921585,地址:北京市東城區(qū)東華門大街], [116.412222,39.912345,地址:北京市東城區(qū)正義路甲5號(hào)] ]; var opts = { width : 250, // 信息窗口寬度 height: 80, // 信息窗口高度 title : 信息窗口 , // 信息窗口標(biāo)題 enablemessage:true//設(shè)置允許信息窗發(fā)送短息 }; for(var i=0;i<data_info.length;i++){ var marker = new bmap.marker(new bmap.point(data_info[i][0],data_info[i][1])); // 創(chuàng)建標(biāo)注 var content = data_info[i][2]; map.addoverlay(marker); // 將標(biāo)注添加到地圖中 marker.addeventlistener(click,openinfo.bind(null,content)); } function openinfo(content,e){ var p = e.target; var point = new bmap.point(p.getposition().lng, p.getposition().lat); var infowindow = new bmap.infowindow(content,opts); // 創(chuàng)建信息窗口對(duì)象 map.openinfowindow(infowindow,point); //開啟信息窗口 } </script>

更多信息請(qǐng)查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:讓ie8瀏覽器支持function.bind()方法
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)