简体   繁体   English

无法在jquery中将焦点更改为滑块

[英]cannot change focus to slider in jquery

I have a function that changes focus whenever a user presses enter. 我有一个功能,只要用户按下回车键就会改变焦点。 This function works great on most pages, but now I have a page with 1 select and 2 sliders (jqueryui). 此功能在大多数页面上都很有效,但现在我有一个包含1个选择和2个滑块的页面(jqueryui)。 When I press enter, focus will not change to a slider. 按Enter键时,焦点不会变为滑块。 A console.log statements show me that my select is returning the correct array of elements: console.log语句向我显示我的select返回正确的元素数组:

0: select#field_odometerunitsselect
1: div#field_fuelquantityrangeslider.ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all
2: div#field_fueldistancerangeslider.ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all

and my javascript is correctly changing to the next element in the array (in this case 1): 并且我的javascript正确地更改为数组中的下一个元素(在本例中为1):

$('#'+inputs.eq(nextinput).id).focus().select();

Can someone tell me why the line above will not change focus to the slider? 有人能告诉我为什么上面的行不会改变焦点到滑块?

To further analyze, I tried manually setting focus with this line 为了进一步分析,我尝试用这条线手动设置焦点

$('#field_fuelquantityrangeslider').focus();

and it too fails. 它也失败了。 So it's not a code problem, it's a slider thing. 所以这不是代码问题,它是一个滑块的东西。 How does one set focus to a slider? 如何将焦点设置为滑块?

您需要定位滑块手柄(请参阅https://stackoverflow.com/a/13692745/786999 ):

$('#field_fuelquantityrangeslider .ui-slider-handle').focus();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM