0
我完全不知道如何使用javascript填充2 <'select>元素。 的一點是,我有這樣一個數組:javascript如何填充從一個數組<select>
Array (
[0] => Array ([0] => 1 [1] => EQual One [2] => Array ([0] => Array ([0] => 1 [1] => 1.7) [1] => Array ([0] => 3 [1] => 1.8) [2] => Array ([0] => 4 [1] => 2.0) [3] => Array ([0] => 5 [1] => 2.1) [4] => Array ([0] => 6 [1] => 2.2)))
[1] => Array ([0] => 2 [1] => NGT [2] => Array ([0] => Array ([0] => 1 [1] => 1.7) [1] => Array ([0] => 3 [1] => 1.8) [2] => Array ([0] => 4 [1] => 2.0) [3] => Array ([0] => 5 [1] => 2.1) [4] => Array ([0] => 6 [1] => 2.2)))
[2] => Array ([0] => 3 [1] => Service [2] => Array ([0] => Array ([0] => 1 [1] => 1.7) [1] => Array ([0] => 3 [1] => 1.8) [2] => Array ([0] => 4 [1] => 2.0) [3] => Array ([0] => 5 [1] => 2.1) [4] => Array ([0] => 6 [1] => 2.2)))
[3] => Array ([0] => 4 [1] => V3D [2] => Array ([0] => Array ([0] => 1 [1] => 1.7) [1] => Array ([0] => 3 [1] => 1.8) [2] => Array ([0] => 4 [1] => 2.0) [3] => Array ([0] => 5 [1] => 2.1) [4] => Array ([0] => 6 [1] => 2.2)))
)
的JS做到這一點: 填充第一場是這樣的:
<select required class="form-control" name="product" id="product" onchange="some action()">
<option value="1">EQualeOne</option>
<option value="2">NGT</option>
<option value="3">Service</option>
<option value="4">V3D</option>
</select>
,並選擇在第二選擇字段應該填充首先要填寫像這樣:
<select required class="form-control" name="product" id="version" >
<option value="value 1 of the array in the array you selected with the select before">XX</option>
<option value="value 2 of the array in the array you selected with the select before">XX'</option>
...
<option value="value X of the array in the array you selected with the select before">XX''</option>
</select>
我很抱歉不beein更準確,但我的英語並不完美。
您希望在選擇中的第一個改變第二個'select'的價值觀的改變?你能否提供一個例子(而不是你的半範例解釋)? –
如果你用JS語法而不是PHP來代表你的數組,那麼這將會更容易回答...... – Alnitak