2
工作選擇選項
所以我有兩個下拉列表:只對第一個下拉
<select id="list1" name="worker" class="form-control select2" style="width: 100%;">
<option selected="selected">Choose one</option>
<?php foreach($names as $name) { ?>
<option value="<?php echo $name['id'] ?>"><?php echo $name['name'] ?></option>
<?php } ?>
</select>
<select id="list2" name="vehicle" class="form-control select2" style="width: 100%;">
<option selected="selected">Choose one</option>
<?php foreach($cars as $car) { ?>
<option value="<?php echo $car['id'] ?>"><?php echo $car['name'] ?></option>
<?php } ?>
</select>
,我有這個jQuery選擇第一個選項,如果只有一條:
var length1 = $('#list1> option').length;
if (length1 < 3) {
$('select>option:eq(1)').prop('selected', true);
}
var length2 = $('#list2 > option').length;
if (length2 < 3) {
$('select>option:eq(1)').prop('selected', true);
}
而且只有工作第一個,即使我只爲第二個腳本。
這works..thanks! :) –
謝謝@NevenGrguric ...':)'! – vijayP