您正在底圖上使用事件,所以我建議將圖釘綁定事件本身,以避免不必要的調用此特定事件。
但是,如果你想更新你的代碼,在這裏是因爲「手」,真正的作品一個完整的例子是在Bing地圖默認元素而鼠標是在基礎地圖,看到代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bing Maps Cursor</title>
<script type="text/javascript" charset="UTF-8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
function getMap() {
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById('map'), {
credentials: "YOURKEY",
center: new Microsoft.Maps.Location(47.5, 2.75),
zoom: 4,
mapTypeId: Microsoft.Maps.MapTypeId.road
});
var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(47.5, 2.75));
map.entities.push(pin);
Microsoft.Maps.Events.addHandler(map, 'mousemove', function(event) {
if(event.targetType === 'pushpin') {
map.getRootElement().style.cursor = 'pointer';
} else {
map.getRootElement().style.cursor = 'url("' + Microsoft.Maps.Globals.cursorPath + 'grab.cur"), move';
}
});
}
</script>
</head>
<body onload="getMap();">
<div id="map" style="position: relative; width: 800px; height: 600px;">
</div>
</body>
</html>
如果你想基於圖釘事件的推薦辦法:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bing Maps Cursor</title>
<script type="text/javascript" charset="UTF-8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
var cursorStyle = null;
function getMap() {
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById('map'), {
credentials: "YOURKEY",
center: new Microsoft.Maps.Location(47.5, 2.75),
zoom: 4,
mapTypeId: Microsoft.Maps.MapTypeId.road
});
var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(47.5, 2.75));
map.entities.push(pin);
Microsoft.Maps.Events.addHandler(pin, 'mouseover', changeCursor);
Microsoft.Maps.Events.addHandler(pin, 'mouseout', revertCursor);
}
function changeCursor(e) {
map.getRootElement().style.cursor = 'pointer';
}
function revertCursor(e) {
map.getRootElement().style.cursor = 'url("' + Microsoft.Maps.Globals.cursorPath + 'grab.cur"), move';
}
</script>
</head>
<body onload="getMap();">
<div id="map" style="position: relative; width: 800px; height: 600px;">
</div>
</body>
</html>
既然你正在處理在底圖上的情況下,你可以有別的情況,並恢復光標默認。 – 2013-04-23 22:35:20