2011-12-14 87 views
0

我想更改下面代碼的區域Id的href更改區域Id的href

<map name="green" id="green"> 
    <area manual_cm_sp="prospect-_-ZarzamoraUITT-_-iwant" href="http://es.t-mobile.com/shop/phones/?action=ADDPROMOTIONALPACKAGE&amp;id=5E725E06-32E7-430E-BA16-0327719DC724&amp;quantity=1" coords="380,419,746,442" alt="Llévate sólo el teléfono HTC Radar 4G" shape="RECT" title="Llévate sólo el teléfono HTC Radar 4G" id="prospectZarzamoraUITTiwant"> 
    <area manual_cm_sp="prospect-_-ZarzamoraUITT-_-iwant" href="http://es.t-mobile.com/shop/phones/?action=ADDPROMOTIONALPACKAGE&amp;id=7BFCC0F4-DF24-4137-85BE-F679A6F0372F&amp;quantity=1" coords="380,446,746,469" alt="Llévatelo con servicio internacional" shape="RECT" title="Llévatelo con servicio internacional" id="Area2"> 
</map> 
+0

什麼是你的問題?獲取對元素的引用?訪問它的`href`屬性?這些都是簡單的操作,每個jQuery教程都應該包含這些操作。查看[ID選擇器](http://api.jquery.com/id-selector/)和[`.attr`](http://api.jquery.com/attr/)方法。閱讀文檔有助於。 – 2011-12-14 19:04:14

回答

0

如果你知道area的id要更改:

$("#Area2").attr('href','newurl.php'); 
+0

我想知道weathert我可以像div ID一樣使用areaId。 – Noname 2011-12-14 19:09:35

0

如果你知道一個元素的ID,你可以選擇它,然後用.attr()來訪問它的屬性:

$('#id-goes-here').attr('href', 'new-href-goes-here'); 

這同樣可以在本地JavaScript來實現:

document.getElementById('id-goes-here').href = 'new-href-goes-here'; 

我建議您檢查出的文檔.attr()http://api.jquery.com/attr(嘿嘿,而你在那裏,爲什麼不瀏覽四周,看看你能學到什麼)