Jquery 选择关注页面加载(onLoad?)
我在选择框上使用 Jquery Chosen 插件,但是我想将其重点放在页面加载上。我使用以下代码来聚焦文本输入:
onLoad="document.forms.sales_order_form.customer.focus()"
但这不适用于选择框:
<select data-placeholder="Select a Customer..." class="chzn-select" name="customer" style="width:400px;">
<option value=""></option>
</select>
I'm using the Jquery Chosen plugin on a select box, however I'd like to focus this on page load. I've used the following code to focus a text input:
onLoad="document.forms.sales_order_form.customer.focus()"
But this doesn't work for the select box:
<select data-placeholder="Select a Customer..." class="chzn-select" name="customer" style="width:400px;">
<option value=""></option>
</select>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在 Chosen 1.0 中,此命令现在为:
请参阅此处。
In Chosen 1.0, this command is now:
See here.
如果您使用第一个示例(标准选择框),您可以使用:
If your using the first example (standard select box) you can use:
Chosen 创建自己的 div 并将您的“
select_ID
”转换为这些 div 的“select_ID_chzn
”Chosen creates owns divs and converts your "
select_ID
" into "select_ID_chzn
" for those divs这对我有用:
或将其缩短为
This worked for me:
or shorten it to
这对我来说完全解决了这个问题:
This fixes the issue completely for me:
这对我有用
this is what worked for me
我一直在 StackOverflow 中搜索此解决方案以在我的一个项目中使用。经过大量搜索后,我学到了一些东西,但没有得到适当的解决方案。最后我解决了我的问题,如下:
我使用
"jquery-1.10.2.min.js"
和"Chosen v1.0.0"
。在我的代码中,我有我的最终代码是:
现在它工作正常。
I have been searching into StackOverflow for this solution to use in one of my project. After searching a lot I have learned something but have got no proper solution. Finally I have fixed my problem as follows:
I am using
"jquery-1.10.2.min.js"
and"Chosen v1.0.0"
. In my code I have<select id="sel_product">
and in jquery$("#sel_product").chosen()
. For adding focus I have added '_chosen' after my ID of the element and call the following function:My final code is:
Now it's working perfectly.
我知道这是一篇旧文章......但就其价值而言,以下也是一个选择......
I know this is an old post... but for what it's worth the following is an option as well...