2013-01-22 108 views
0

我有一個div從PHP填充我試圖綁定在一個div中的所有輸入框變量,(我不希望使用序列化)我如何使用jquery來選擇每個和將其綁定到變量如Jquerying使用兒童選擇器

var location_id = $('#Wednesday').find('input').nth-child(0); 
var static_id =$('#Wednesday').find('input').nth-child(1); 

這種性質的感謝!

<div id='Wednesday' class='ui-widget-content ui-state-default' name='' value=''> "; 

echo "<input name='".$day."_".$locationid."_locationID' value='".$locationid."' type='hidden'> "; 
echo "<input name='".$day."_".$locationid."_static' value='".$static."' type='hidden'> "; 
echo "<input name='".$day."_".$locationid."_primary' value='".$first_always."' type='hidden'> "; 
echo "<input name='".$day."_".$locationid."_all_locations' value='".$all_locations."' type='hidden'> "; 

</div> 

回答

1
var inputs = $('#Wednesday').find('input'); 

var location_id = inputs.eq(0).val(); 
var static_id = inputs.eq(1).val(); 
+0

你是正確的先生,我需要val(); – Edward

0

使用.eq而不是.nth-child()

+0

它給我[對象對象]作爲返回值。 – Edward

+0

@愛德華你想要什麼? '.eq(number).val()'怎麼樣? –

1

作爲一個側面說明(因爲你已經有了你的答案),任何時候我看到一種形式的輸入名稱相似,你有什麼:

'name="' . $day . '_' . $location_id . '_locationID"' 

它的尖叫聲給我看,這可能情況下,您應該使用這樣的陣列式的形式輸入的情況下:

'name="locationID[' . $day . '][' . $location_id . ']"' 

在PHP這樣的話,你已經爲你建立了一個很好的數組中$_POST,你不需要explode()從所有輸入字段中構建數組。

+0

謝謝,我會牢記它。 – Edward