2009-10-13 51 views
0

這段代碼將循環數次。檢索Div中的每個值

當任何用戶選擇任何單選按鈕時,我想查找選中哪個單選按鈕。

隨着選定的索引,我想得到address_<selectedIndex> object;。現在我想訪問它的兄弟姐妹div值,如addressLine_1,addressLine_2,addressLine_3,city,state,zip在一個變量中。

請幫我寫這段jQuery腳本。

<div class="address"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
     <td width="8%" align="center"><input type="radio" name="addressSelected" value="1" /></td> 
     <td class="address_0" width="92%"> 
      <div class="addressLine_1">gotomedia LLC</div> 
      <div class="addressLine_2">2169 FOLSOM ST</div> 
      <div class="addressLine_3">STE M301</div> 
      <div class="city floatLeft">SAN FRANCISCO</div> 
      <div class="state floatLeft">&nbsp;CA</div> 
      <div class="zip floatLeft">&nbsp;94110</div> 
     </td> 
    </tr> 
    </table> 
</div> 
+0

請添加更多代碼,最好是包含您正在討論的單選按鈕的內容。 – inkedmn 2009-10-13 13:31:26

+1

SO願意*幫助你的家庭作業,但我們不會爲你做*。 – 2009-10-13 13:32:57

回答

1

我想這將是你的解決方案。 由於此代碼檢查$(this).val() == "1",您必須注意輸入字段的值。也許你必須修改它。

var values = []; 
$("input[name=addressSelected]:checked") 
    .filter(function() { return $(this).val() == "1" }) 
    .parent()   // the parent td 
    .siblings()   // the other tds 
    .children("div") // the divs 
    .each(function() { values.push ($(this).text) }); 

這應該做的伎倆

你可能會改變每一行:

.each(function() { values[ this.className ] = $(this).text }); 

這樣你就可以訪問它想:values['addressLine_1']然而,你將不得不刪除您的浮動類的好結果