0

I'm trying to have jQuery grab a handful of li elements based upon class.

Everything is running smoothly in FF and IE, however webkit browsers don't fire the click event. I've run the code through JSLint, it comes back valid, I also get no errors via the console in Chrome.

All code is viewable at http://jsfiddle.net/Yq3d9/12/

$(document).ready(function () {
    $('#countryList option').click(function () {
        var myCountry;
        $('#countryList').change(function () {
            myCountry = $(this).val();
        }).change();
        $('#premier ul, #popular ul, #recommended ul, #supported ul').empty();
        $('.' + myCountry + '.Popular').clone().appendTo('#popular ul');
        $('.' + myCountry).not('.Premier, .Popular').clone().appendTo('#supported ul');
        $('#Display div, #premier ul, #popular ul, #supported ul').removeClass();
        $('#Display div').addClass(myCountry);
    });
    $('#expandButton').click(function () {
        $('#supportedWrapper').animate({
            height: ($('#supported').height() + 100)
        }, 1200);
    });
});
4

2 回答 2

3

处理下拉菜单的change事件:

$(document).ready(function () {
    $('#countryList').change(function () {
        var myCountry = $(this).val();
        $('#premier ul, #popular ul, #recommended ul, #supported ul').empty();
        $('.' + myCountry + '.Popular').clone().appendTo('#popular ul');
        $('.' + myCountry).not('.Premier, .Popular').clone().appendTo('#supported ul');
        $('#Display div, #premier ul, #popular ul, #supported ul').removeClass();
        $('#Display div').addClass(myCountry);
    });
    $('#expandButton').click(function () {
        $('#supportedWrapper').animate({
            height: ($('#supported').height() + 100)
        }, 1200);
    });
});

演示:http: //jsfiddle.net/XS5Bz/

我不确定您要对<option>单击的单个 s 做什么,但这不是必需的,并且change每次<option>单击 a 时您都会将一个新事件绑定到下拉列表...这是矫枉过正且不完全正确.

change事件在您更改 selected 时发生<option>,因此它应该是您所需要的。

于 2013-04-17T16:32:02.517 回答
0

change只需将事件绑定到<select>元素就足够了,而不是获取当前值并触发更改的复杂方式。这是一个工作小提琴

http://jsfiddle.net/Yq3d9/13/

于 2013-04-17T16:34:54.223 回答