使用jQuery在预填充的表单字段上设置焦点

使用jQuery在预填充的表单字段上设置焦点,jquery,html,forms,select,focus,Jquery,Html,Forms,Select,Focus,当加载包含表单的页面时,第一个输入文本字段具有值,焦点将自动跳到第二个字段 如何在第一个字段上设置焦点并选择预填充的文本/值我不希望光标位于预填充文本/值的末尾。使用自动对焦: <form name="test"> <label for="name">Name</label> <input type="text" name="name" value="Alexandre" autofocus /> <label fo

当加载包含表单的页面时,第一个输入文本字段具有值,焦点将自动跳到第二个字段

如何在第一个字段上设置焦点并选择预填充的文本/值我不希望光标位于预填充文本/值的末尾。

使用自动对焦:

<form name="test">
    <label for="name">Name</label>
    <input type="text" name="name" value="Alexandre" autofocus />

    <label for="email">E-mail</label>
    <input type="email" name="email" value="" />
</form>

名称
电子邮件

请参阅要使用的解决方案

$(yourElement).select();
问题是,一些自制的对话框框架将我正在使用的$(document).ready(function(){…})转换为foobar


通过将my.select()移动到处理后加载的dialog framework函数,我可以解决问题。

您使用的浏览器是什么?不幸的是,我看不到你的小提琴,也看不到我的表单在firefox(24.3)中工作。我使用Chrome33,但我在Firefox27.0.1中进行了测试,它也可以工作。