开发者

JQuery dropdown works on Firefox but not on Google Chrome

开发者 https://www.devze.com 2023-01-20 08:08 出处:网络
First the code might suck as I\'m new with JQuery. I have this html: <select name=\"numberItems\" id=\"id_numberItems\">

First the code might suck as I'm new with JQuery. I have this html:

<select name="numberItems" id="id_numberItems"> 
<option value="1" selected="selected">1</option> 
<option value="2">2</option> 
<option value="3">3</option> 
<option value="4">4</option> 
<option value="5">5</option> 
</select>
<fieldset class="dropdownList"> 
     [...]
</fieldset>
<fieldset class="dropdownList"> 
     [...]
</fieldset>  <!-- This fieldset is repeated 5 times -->

This is my Jquery code:

// Dropdown
function dropDown(val) {
    $('.dropdownList').hid开发者_开发知识库e();
    $('.dropdownList:lt(' + val + ')').show();
}

$("#id_numberItems").click(function() { dropDown($('#id_numberItems').val()) });

This dropDown thing is working on Firefox, but not in Google Chrome ¿why? Thanks


Attach your dropDown-function to the change-event of your dropdown and it should work the way you want it (or as my crystal ball suggests me...)

$("#id_numberItems").change(function() { dropDown($('#id_numberItems').val()) });

example on jsbin.com

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号