如何使用jQuery重置选择的多选字段? [英] How do you reset a Chosen multiple select field using jQuery?

查看:57
本文介绍了如何使用jQuery重置选择的多选字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个选择字段的表单,使用Formtastic和Chosen创建。

I have a form with a multiple select field, created using Formtastic and Chosen.

此表单有一个多选字段,这里是rails代码:

This form has a multiple select field, here is the rails code for it:

 = semantic_form_for 'post', :url => action_name_post_path(@post), :html => {:method => :put}, :remote => true do |f|
    = f.input :blogs, :label => _("Blog"), :as => :select, :multiple => :true, :input_html => {:class => "chzn-select"}, :collection => Blog.all

我想使用jQuery重置输入字段(表单已提交并远程重置),我似乎无法弄清楚如何删除所选元素//清除输入字段。问题是选择更改输入字段,因此它不是一个简单的文本区域。

I would like to reset the input field using jQuery (the form is submitted and reset remotely), and I can't seem to figure out how to remove the selected elements//clear the input field. The issue is that chosen changes the input field so it isn't a simple text area.

有人能指出我正确的方向吗?

Can anyone point me in the right direction?

推荐答案

试试这个

$('.chzn-select').val('').trigger('liszt:updated');

这篇关于如何使用jQuery重置选择的多选字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆