我有一个非常复杂的图像映射,我想缩小一半。这样做需要将所有坐标值除以 2。由于有数千个坐标值,我想我可以使用 jQuery 遍历 DOM 来找到坐标值,然后将它们除以 2。当谈到 JavaScript 和 jQuery 时,我非常业余,我编写了以下代码,但无法完成我的任务:
$(function(){
$('area').each(function(){
coord_vals= $('area'[coords]).split(',');
new_vals= coord_vals/2;
$('area'[coords]).val(new_vals + ',');
});
});
这是我试图遍历的前几行 HTML:
<div id="map">
<img class="map" src="images/us_map.jpg" width="960" height="593" usemap="#usa">
<map name="usa">
<area href="#" title="SC" shape="poly" coords="735,418, 734,419, 731,418, 731,416, 729,413, 727,411, 725,410, 723,405, 720,399, 716,398, 714,396, 713,393, 711,391, 709,390, 707,387, 704,385, 699,383, 699,382, 697,379, 696,378, 693,373, 690,373, 686,371, 684,369, 684,368, 685,366, 687,365, 687,363, 693,360, 701,356, 708,355, 724,355, 727,356, 728,360, 732,359, 745,358, 747,358, 760,366, 769,374, 764,379, 762,385, 761,391, 759,392, 758,394, 756,395, 754,398, 751,401, 749,404, 748,405, 744,408, 741,409, 742,412, 737,417, 735,418"></area>
<area href="#" title="HI" shape="poly" coords="225,521, 227,518, 229,517, 229,518, 227,521, 225,521"></area>
<area href="#" title="HI" shape="poly" coords="235,518, 241,520, 243,520, 244,516, 244,513, 240,512, 236,514, 235,518"></area>