【发布时间】:2017-07-29 12:03:57
【问题描述】:
我有一个选择下拉列表和 2 个输入字段。我知道如何使用以下方法将焦点设置在任何模式的第一个输入字段上:
$('.modal').on('shown.bs.modal', function () {
$(this).find('input:text:visible:first').focus();
})
https://www.w3schools.com/code/tryit.asp?filename=FDG195P90CWU
但是当同时存在下拉列表和输入字段时,我看不到该怎么做。
【问题讨论】:
-
那么当你加载模态框时,你希望选择被聚焦吗?
-
@pasquers 是,但如果它是第一个元素
-
所以我可能不完全理解要求,但我相信这会做你想要的: .modal-body > select:first, .modal-body > input:first 这样,不管如果如果它是第一个元素,它将被选择,它是一个选择或输入。唯一的要求是它必须是直接孩子
-
@pasquers 我想是的,谢谢,会尝试(我是初学者)
-
this is not actually working when the select isn't present because the input isn't a direct descendant, I'll have to re think through this
标签: javascript jquery css twitter-bootstrap