粗略的数了一下
大概有一百多个变量、二十多个函数,下面是函数列表
function createMapSpecs()
function _ua(t)
function _uan(t)
function _noActiveX()
function _compat()
function _browserIsCompatible()
function GBrowserIsCompatible()
function _havexslt()
function _script(src)
function GLoadMapsScript()
function _el(i)
function _esc(v)
function _loadnxsl()
function _load(xml, doc, loc, home)
function _print()
function _createMap()
function _checkLoad()
function getDirectionsStart()
function getDirectionsEnd()
function qs(el)
function qs(el)
function qs(el)
函数
其中很多函数是用来检测浏览器的兼容性的
function _ua(t)
function _uan(t)
function _noActiveX()
function _compat()
function _browserIsCompatible()
function GBrowserIsCompatible()
function _havexslt()
其中有些是辅助函数有些是主要函数,我将主要函数代码贴出来
function _compat(){
return ((_ua('opera') &&(_ua('opera 8') || _ua('opera/8'))) ||(_ua('safari') && _uan('safari/') >= 125) ||(_ua('msie') &&!_ua('msie 4') && !_ua('msie 5.0') && !_ua('msie 5.1') &&!_ua('msie 3') && !_ua('msie 5.5') && !_ua('powerpc')) ||(document.getElementById && window.XSLTProcessor &&window.XMLHttpRequest && !_ua('netscape6') &&!_ua('netscape/7.0')));
}
它引用了_ua()函数,那_ua()是用来干什么的呢?让我们来看下面的代码
var _u = navigator.userAgent.toLowerCase();
function _ua(t) {
return _u.indexOf(t) != -1;//更多关于indexof看文章最后
}
_ua(t)来检测用户的浏览器型号中是否含有(t)字符
_compat()呢就是用来检测用户是不是这么多浏览器中的一种。
function _el(i)
{
return document.getElementById(i);
}
这个函数实际上更多是为了减少代码长度,因为google就是通过getElementById(i)来控制不同页面元素的显示与隐藏的,这个函数用的很频繁,申明一个短点的函数很有必要。
function _script(src)
{
var ret='<'+'script src="'+src+'"'+' type="text/javascript"><'+'/script>';document.write(ret);
}
这个函数很明显是用来引用地址为src的脚本文件的。它在function GLoadMapsScript()被调用。
function GLoadMapsScript()
{
if (_havexslt()){_script("http://maps.google.com/mapfiles/maps.28.js");
}
else if (_ua('safari'))
{
_script("http://maps.google.com/mapfiles/maps.28.safari.js");
}
else
{
_script("http://maps.google.com/mapfiles/maps.28.xslt.js");
}
}
这个函数被用来调用google map的主引擎,时间所限这几个文件旷野还没来得及看了,这几个文件google在不断更新,今天我看时已经是29了。google的开发速度还是非常快的。呵呵。
function _createMap()
{
var mapSpecs = createMapSpecs();
_m = new _MapsApplication(_el('map'),_el('panel'),_el('linktopage'),_el('printheader'),_el('printpanel'),mapSpecs);
_m.loadMap();
_m.manageFocus(_el('q'));
_m.manageFocus(_el('what'));
_m.manageFocus(_el('where'));
_m.manageFocus(_el('start'));
_m.manageFocus(_el('end'));
_m.registerForm('maps',_getElementsByClassName('maps_tab'),_el('maps_card'),_el('maps_form'),_el('q'));
_m.registerForm('local',_getElementsByClassName('local_tab'),_el('local_card'),_el('local_form'),_el('what'));
_m.registerForm('directions',_getElementsByClassName('directions_tab'),_el('directions_card'),_el('directions_form'),_el('start'));
_Event.bindDom(_el('where'), 'blur', _m, _m.wblur);
_Event.bindDom(_el('where'), 'focus', _m, _m.wfocus);
_el('maps_form').target = "vp";
_el('local_form').target = "vp";
_el('directions_form').target = "vp";
}
在页面的最后这个函数被调用,创建了map所需要的页面元素 div等等 ,由于_MapsApplication代码在另外的文件中,所以此处就不再说明了,但大家可以注意一下大量出现的_el(' ... ')。
局部刷新
旷野发现当用户需要在
Search the map
Find businesses
Get directions
JScript .NET
indexOf 方法
返回 String 对象内第一次出现子字符串的字符位置。 function indexOf(subString : String [, startIndex : Number]) : Number 参数
备注indexOf 方法返回一个整数值,该值指示 String 对象内子字符串的起始位置。如果未找到子字符串,则返回 -1。 如果 startindex 为负,则将 startindex 视为零。如果它比最大字符位置索引还大,则将它视为可能的最大索引。 搜索将从左向右执行。否则,此方法与 lastIndexOf 相同。 示例下面的示例阐释了 indexOf 方法的用法。 function IndexDemo(str2){ var str1 = "BABEBIBOBUBABEBIBOBU" var s = str1 |