开发者

scrollTop not working in browsers other than Firefox

开发者 https://www.devze.com 2023-03-19 17:25 出处:网络
The scrollTop function in jQuery for select list is working only in Firefox. In other browsers it\'s not working.

The scrollTop function in jQuery for select list is working only in Firefox. In other browsers it's not working.

For example

<select id="mySelect">
<option value="1">1</option>开发者_开发问答;
<option value="2">2</option>
...
<option value="100">100</option>
</select>

$('#mySelect').click(function(){
         $(this).scrollTop(150);
});

Does anybody know how to resolve this problem so it works across all browsers?


Try this

$('#mySelect').click(function(){
    var $options = $(this).find("option");
    $options.eq(($options.length)/2)[0].selected = true;
});


It could be that the select box doesn't support a click event in some browser? I'm assuming you want the browser to scroll to the that section of the page and then let them make a selection. You could try a change or focus event instead.

0

精彩评论

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