繁体   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