最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery chosen - on click dont work - Stack Overflow

programmeradmin9浏览0评论

I'm using chosen JQuery plugin, i would like when the user click on the select box; do something (load data from data base into the select box).

HTML

<select name="mysection" id="mysection" class="chosen-select-deselect">
</select>

JS

$('#mysection').live('click',function(){             
alert("hello for test");             
})

I tried to just test if the event work or not, but it seems not working

NB: i'm using jquery 1.6.4

I'm using chosen JQuery plugin, i would like when the user click on the select box; do something (load data from data base into the select box).

HTML

<select name="mysection" id="mysection" class="chosen-select-deselect">
</select>

JS

$('#mysection').live('click',function(){             
alert("hello for test");             
})

I tried to just test if the event work or not, but it seems not working

NB: i'm using jquery 1.6.4

Share Improve this question asked Feb 17, 2014 at 15:28 MDITMDIT 1,5486 gold badges25 silver badges38 bronze badges 11
  • 1 I would remend you to upgrade to latest version of jQuery soon! – Chethan N Commented Feb 17, 2014 at 15:31
  • What is your console saying? Any error log? Can you provide a fiddle, because this should work. And yeap you should update you jQuery library – Emil Borconi Commented Feb 17, 2014 at 15:32
  • Upgrade to a newer jquery... Also, what does your console say? Is it showing any problems? – buzzsawddog Commented Feb 17, 2014 at 15:32
  • @RobSchmuecker that wont work he is in 1.6.4 – buzzsawddog Commented Feb 17, 2014 at 15:33
  • there is no problem in the console !! – MDIT Commented Feb 17, 2014 at 16:09
 |  Show 6 more ments

1 Answer 1

Reset to default 5

While dealing with the selectmenus or check boxes use 'change'.

here is the code

HTML

<select name="mysection" id="mysection">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>

JS

$(document).ready(function () {
    $("#mysection").chosen();
    $('#mysection').live('change', function () {
        alert($(this).val());
    });
});

CSS

#mysection {
    width: 100px;
}

Try the above code, it will work :)

EDIT

when you use chosen, it converts select into another div after it, you can even use

$("#mysection_chosen").bind("click", function ()

or

$("#mysection").next().bind('click', function ()
发布评论

评论列表(0)

  1. 暂无评论