使用选定的jQuery插件获取每个选定的值 [英] Get each selected value using chosen jquery plugin

查看:71
本文介绍了使用选定的jQuery插件获取每个选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用选择的多项选择我想做的是,如果用户选择任何选项,我都需要该值,然后我将根据该值执行一些功能.

I'm using Chosen Multiple Select What I want to do is that if user selects any option I want that value and then I will do some functionality depending on that value.

在没有多选的情况下,我可以使用foll获得选定的值.代码

In chosen without multiple select i can get selected value by using foll. code

$(".selectId").chosen().change(function(){
     selectedValue = $(this).find("option:selected").val();
});

但是在多次选择中,我再次获得第一个选择的值n有人可以通过在多个选择元素中找到当前选择的值来帮助我吗?

But in multiple select I get the first selected value again n again can anybody help me by finding the current selected value in multiple select element??

推荐答案

选择的文档提到了获取最新更改的变量.

The Chosen documentation mentions parameters for getting the most recently changed variables.

选择后,选择触发标准DOM事件(它还会发送一个选定或取消选定的参数,告诉您哪个选项已更改).

Chosen triggers the standard DOM event whenever a selection is made (it also sends a selected or deselected parameter that tells you which option was changed).

因此,如果您只想选择或取消选择最新选项:

So, if you just want the most recent option selected or deselected:

$(".selectId").chosen().change(function(e, params){
 // params.selected and params.deselected will now contain the values of the
 // or deselected elements.
});

否则,如果您想使用整个数组,则可以使用:

Otherwise if you want the whole array to work with you can use:

$(".selectId").chosen().change(function(e, params){
 values = $(".selectId").chosen().val();
 //values is an array containing all the results.
});

这篇关于使用选定的jQuery插件获取每个选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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