简体   繁体   English

自动选择输入字段

[英]Automatically Selecting Input Field

So I have a Javascript form using a Date picker: 所以我有一个使用日期选择器的Javascript形式:

<input name="date" type="date" id="date"/>

I would like the input field to already be selected when the screen loads. 我希望在屏幕加载时已经选择了输入字段。 Scenario: user on an iOS device loads this form, and the Date Picker automatically comes up, without them having to tap on the drop down element in the HTML. 场景:iOS设备上的用户加载此表单,然后自动出现Date Picker,而无需点击HTML中的下拉元素。

Any ideas? 有任何想法吗?

Thanks. 谢谢。

You need to use the focus() method, then you can set the focus on your input on body load, as follow: 您需要使用focus()方法,然后可以将焦点设置在身体负荷的输入上,如下所示:

<input class=".dtInput" name="date" type="date" id="date"/>

<script type="text/javascript">
    $('body').onload(function(){
        $('.dtInput').focus();
    }
</script

Use the jquery to easily get the elements of you page 使用jquery轻松获取您页面的元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM