簡體   English   中英

如何預選 <option>上下文?

[英]How to preselect an <option> contextually?

我的html中有很多.fare類的實例。 因此,我在上下文中實施該解決方案。 對於某些票價,我想自動在.fare選項列表中選擇第二個值(所有票價)並禁用選擇框。

選項是:options_fare =“選擇票價”所有票價“”

但是,當我嘗試以下代碼時,它停留在選項1(選擇票價)上。

$contextualDiv.children('.fare').html(options_fare);
$contextualDiv.children('.fare option:eq(1)').attr('disabled', false).prop('selected', true).trigger('change');
    }

我在這里想念什么?

非常感謝!

改變你的:

$contextualDiv.children('.fare option:eq(1)')

$contextualDiv.children('.fare').children('option:eq(1)')

要么

$contextualDiv.find('.fare option:eq(1)')

children之所以沒有為您的事業而工作的原因,是因為children只看一級孩子,而不看孩子的孩子進行深入搜索,而是使用find

工作實例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM