gpt4 book ai didi

javascript - Jquery 在单击时将自动对焦添加到字段

转载 作者:行者123 更新时间:2023-11-29 20:50:46 28 4
gpt4 key购买 nike

我有多个带有表单的模式,我希望当我点击其中一个时,它会将属性 autofocus 赋予第一个 visible 输入字段。因为表单中还有隐藏的输入字段。

我使用 MaterializeCSS 来生成模态框。我已经设置好了:

$('#modal-entry').modal({
onOpenEnd: function () {
alert('The autofocus needs to be added in this line');
}, // Callback for Modal open
});

最佳答案

用这个替换您的警报,您当然需要您的表单选择器或包含您的表单的容器。

  • 使用not以避免专注于隐藏的输入。
  • 使用first获取输入选择器列表中的第一个输入

$('#form input').not(":hidden").first().focus();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form">
<input type="hidden"/>
<input type="text" placeholder="name"/>
<input type="text" placeholder="lastname"/>
</form>

关于javascript - Jquery 在单击时将自动对焦添加到字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52002899/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com