可点击的美国地图绑定到多选ListBox -jQuery点击事件未触发

时间:2014-11-22 09:43:41

标签: javascript imagemap

<html>
<head><title>Image Map</title>
</head>

<body>
Welcome to USA Map<br><br>
Click on Map to find out <br><br>

<script type="text/javascript">
$(function() { //run when the DOM is ready
    $("#planetmap area").click(function (e) {
    // jQuery code, event handling callbacks here
 alert();
});
});
</script>
<select id="listbox" size="5" multiple>
<option value="none">Take a pick on the map</option>
<option value="wyoming">Wyoming</option>
<option value="arizona">Arizona</option>
</select>
<img src="usaStateMap.jpg" alt="usa" usemap="#planetmap"/>
<map name="planetmap" id="planetmap">
<area id="wyoming" alt="Wyoming" title="Wyoming" href="#" shape="poly" 
coords="203,125,192,188,278,198,284,136" />
<area id="arizona" alt="Arizona" title="arizona" href="#" shape="poly" 
coords="138,258,118,330,188,361,201,269" />

</map>
</body>
</html>

地图将在父窗口的子窗口和列表框中启动。 在Javascript的点击事件上,我希望能够在列表框中多选择相同的项目(状态)。你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

<script src="jquery.js"></script>

<script type="text/javascript">
 $(function() { //run when the DOM is ready
 $("#planetmap area").click(function (e) {
 // jQuery code, event handling callbacks here
   $('#mymapselect option[value="' + this.id + '"]').attr('selected', 'selected');

 });
 });
</script>

我从http://learn.jquery.com/about-jquery/how-jquery-works/#jQuery:_The_Basics下载了jquery.js文件 并添加作为参考。现在,click事件适用于Imagemap区域。它会多选集列表框中的项目。

相关问题