通过选择的jQuery更新选择 [英] Update a select via Chosen Jquery

查看:66
本文介绍了通过选择的jQuery更新选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对selected.jquery.js有问题 当我尝试动态更新列表并在下面编写代码

I have an issue with chosen.jquery.js when i try to update a list dynamically and write the code below

$(selector).trigger("chosen:updated");

它工作正常,但仅更新选择 因此这些值仍然呈现不变,没有变化

it works fine, but updating only the select so the values rendered still as they are with no change

由于呈现的值是从除更新后的select之外的div中的(ul)获取的

as the rendered values got from a (ul) placed in a div besides the updated select

我如何更新渲染的值?

推荐答案

.append(...)之后添加了.trigger('chosen:updated');,以便选择更改"现在显示在选择框中.

Added .trigger('chosen:updated'); after .append(...) so that "select changed" now shows up in the selection box.

$('#Groups').chosen().change(function (evt, params) {
    $('#Groups').append($("<option/>", {
        value: "test",
        text: "select changed"
    })).trigger('chosen:updated');
});
$('.chosen').empty().trigger('chosen:updated');

$('#Groups').append($("<option/>", {
        value: "1",
        text: ""
    }));
$('#Groups').append($("<option/>", {
        value: "2",
        text: "2"
    }));
$('#Groups').append($("<option/>", {
        value: "3",
        text: "3"
    }));
$('.chosen').trigger('chosen:updated');

这是您要找的吗? http://jsfiddle.net/8wykf44s/2/

这篇关于通过选择的jQuery更新选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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