zlb

javascript 常用方法

attachEvent 邦定事件时传参数

 attachEvent   ('onmouseover',   new   Function("Somefuc(someparma);"));  

 

//javascrip 读xml文件  

代码
function getDataPushpin() {
    
var xmlDoc;

    
if (window.ActiveXObject) {
        
//获得操作的xml文件的对象 
        xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
        xmlDoc.async 
= false;
        xmlDoc.load(
"XMLData/XMLMapsPushpin.xml");
        
if (xmlDoc == null) {
            alert(
'您的浏览器不支持xml文件读取,于是本页面禁止您的操作,推荐使用IE5.0以上可以解决此问题!');
            window.location.href 
= '/Index.aspx';
            
return;
        }
    }
    
//解析xml文件,判断是否出错 
    if (xmlDoc.parseError.errorCode != 0) {
        alert(xmlDoc.parseError.reason);
        
return;
    }
    
//获得根接点 
    var nodes = xmlDoc.documentElement.childNodes;
    
//得到根接点下共有子接点个数,并循环 
    for (var i = 0; i < nodes.length; i++) {
        
//如果接点名为 Pushpin
        if (nodes(i).nodeName == "Pushpin") {
            readPushpin(nodes(i));
        }      
        }
          
//删除对象 
        delete (xmlDoc);
        
return;
    }
    
//读Pushpin节点 
    function readPushpin(cI) {
        
var nodes = cI.childNodes;
        
var title;
        
var description;
        
var x;
        
var y;
        
//得到Pushpin标题
        if (cI.selectNodes("Title")(0).text != "") {
            title 
= cI.selectNodes("Title")(0).text;
        }
        
//得到Pushpin备注
        if (cI.selectNodes("Description")(0).text != "") {
            description 
= cI.selectNodes("Description")(0).text;
        }
        
//得到Pushpin经度
        if (cI.selectNodes("VELatLongLatitude")(0).text != "") {
            x 
= cI.selectNodes("VELatLongLatitude")(0).text;
        }
        
//得到Pushpin纬度
        if (cI.selectNodes("VELatLongLongitude")(0).text != "") {
            y 
= cI.selectNodes("VELatLongLongitude")(0).text;
        }
        
//添加pushpin
        var currentPixel = new VELatLong(x, y);
        
var pin = map.AddPushpin(currentPixel);
        pin.SetTitle(title);
        pin.SetDescription(description);
        
return;
    } 

 

 ////////////////////////////////////////////////////////////////////////////////////////////////

//xml文件 

代码
<?xml version="1.0" encoding="utf-8" ?>
<Pushpins>
  
<Pushpin>
    
<Title>标题</Title>
    
<Description>备注</Description>
    
<!--经度-->
    
<VELatLongLatitude>34.59704151614415</VELatLongLatitude>
    
<!--纬度-->
    
<VELatLongLongitude>108.19335937499998</VELatLongLongitude>    
  
</Pushpin>
  
<Pushpin>
    
<Title>标题1</Title>
    
<Description>备注1</Description>    
    
<VELatLongLatitude>40.64730356252251</VELatLongLatitude>   
    
<VELatLongLongitude>111.796875</VELatLongLongitude>
  
</Pushpin>
  
<Pushpin>
    
<Title>标题2</Title>
    
<Description>备注2</Description>
    
<VELatLongLatitude>30.448673679287544</VELatLongLatitude>
    
<VELatLongLongitude>114.34570312499998</VELatLongLongitude>
  
</Pushpin>
  
<Pushpin>
    
<Title>标题3</Title>
    
<Description>备注3</Description>
    
<VELatLongLatitude>30.77133907653231</VELatLongLatitude>
    
<VELatLongLongitude>112.83302307128909</VELatLongLongitude>
  
</Pushpin>
</Pushpins> 

 

 

posted on 2010-04-29 14:35  zlb  阅读(193)  评论(0编辑  收藏  举报

导航