Chosen: .chosen().change() 不工作

创建于 2011-12-07  ·  8评论  ·  资料来源: harvesthq/chosen

嗨,我想使用 AJAX 根据在另一个中选择的值更新一个选择中的选项。

我的底层 AJAX 代码在标准选择上运行良好,但是当我尝试以下两个代码片段中的任何一个来触发更改时,它不起作用。

我在页面加载时收到警报(),但当我更改 ID 为“类别”的选择值时却没有

[代码]

$("#categories").chosen().select(alert());
$("#categories").chosen().change(alert());

[/代码]

所有8条评论

通过包裹它来修复

$(文档).ready(函数() {

});

我看到了同样的行为 - 我把它包裹在:

$(document).ready(function() {
    $(".chzn-select").chosen().select(alert());
});

我正在使用 jquery 1.7.1

@samkuehn

山姆 - 你能解决这个问题吗? 我现在正在使用它,下面的代码没有在我的控制台中记录任何内容。

$(document).ready(function () {
    $('#season').chosen().change(function () {
        console.log('asdf');
    });
});

@bkuhl已经有一段时间了,但我认为这最终对我

$(".chzn-select").chosen().change(function (event) {
    log('change', event, $(event.target).val());
});

回滚到 0.9.5 版本对我有帮助 :)

  var choice, close_link,
                _this = this;
            choice = $('<li />', {
                "class": "search-choice"
            }).html("<span>" + item.html + "</span>");
            if (item.disabled) {
                choice.addClass('search-choice-disabled');
            } else {
                close_link = $('<a />', {
                    "class": 'search-choice-close',
                    'data-option-array-index': item.array_index
                });
                close_link.bind('click.chosen', function(evt) {
                    return _this.choice_destroy_link_click(evt);
                });
                choice.append(close_link);

想问一下,如何在<span>添加Class?

这对我来说非常有效。 如果有人在寻找 CoffeeScript 的实现,它在这里:

$('.myselect').chosen().change(
    (event) ->
        console.log "data changed"
)  

我在这里也有同样的事情。 没有解决方案对我有用!

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

YANOUSHek picture YANOUSHek  ·  25评论

donthebike picture donthebike  ·  41评论

mrpohoda picture mrpohoda  ·  25评论

MB34 picture MB34  ·  22评论

silkfire picture silkfire  ·  53评论