scrollTop not working in browsers other than Firefox
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.
精彩评论