jQuery UI Multiselect如何获取选定的选项值 [英] JQuery UI Multiselect how to get selected options values

查看:411
本文介绍了jQuery UI Multiselect如何获取选定的选项值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索如何获取Michael Aufreiter的JQuery UI小部件中的选定选项值时浪费了我的一天.这是他的演示站点和github的链接: http://quasipartikel.at/multiselect/

wasted my day while searching how to get selected options values in JQuery UI widget by Michael Aufreiter. Here's the link to his demo site and github: http://quasipartikel.at/multiselect/

因此,我只需要选定选项的值字段,而无需将POST/GET发送到PHP脚本. 我尝试了许多方法,但没有结果. 需要您的帮助和想法

As a result I just need value fields of selected options without POST/GET sendings to PHP script. I tried many methods and resultless. Need your help and ideas

*发现了许多有关jquery ui multiselect的主题,但是由于Aufreiter:s *没有用

*Found many topics about jquery ui multiselect but useless because of Aufreiter :s *

推荐答案

我去到了上面列出的网站,并且能够在我的chrome控制台中运行它:

I went to the site you've got listed above, and was able to run this in my chrome console:

$('.ui-multiselect .selected li').each(function(idx,el){ console.log(el.title); });

似乎想要的值存储在div.selected元素内列表项的title属性中.

It seems like the values you want are stored in the title attributes of the list items within the div.selected element.

Do!当然,您需要这些值.不好意思,朋友.完全错过了.真实商品存储在 jQuery data()对象中.在这种情况下,您想要的密钥是"optionLink".它维护对选项元素的引用. ".selected" div中的每个列表项都使用jQuery.data()方法向其添加基础选项.

Doh! Well of course you want the values. Sorry mate. Completely missed that. The real goods are stored in the jQuery data() objects. In this case, the key you want is 'optionLink'. It maintains a reference to an option element. Each list item in the '.selected' div used the jQuery.data() method to add the underlying option to it.

因此,您需要获取选定的列表项,进行遍历,从数据jQuery数据存储区中获取"optionLink",然后获取值.

So, you need to get the selected list items, iterate through, grab the 'optionLink' from the data jQuery data store, and then get the value.

以下代码在示例页面上有效:

The following code works on the example page:

$('.ui-multiselect .selected li').each(function(idx,el){
    console.log(el);
    var link = $(el).data('optionLink');
    // link now points to a jQuery wrapped <option> tag


    // I do a test on link first.  not sure why, but one of them was undefined.
    // however, I got all four values.  So I'm not sure what the first <li>
    // is.  I'm thinking it's the header...
    if(link){

        // here's your value. add it to an array, or whatever you need to do.
        console.log(link.val());
    }

});

这是我第一次看到多重选择.光滑.但是我很同情您试图解决问题的挫败感.一个'getSelectedOptions()'方法会很好.

This is the first I've seen of the multiselect. It's slick. But I sympathize with your frustration trying to get something out. A 'getSelectedOptions()' method would be nice.

欢呼

这篇关于jQuery UI Multiselect如何获取选定的选项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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