在以下呼叫功能onSelectEvent:
负责处理&切换选项。我正在尝试通过此变量获取选项值,但调用函数中的此变量会冻结选择菜单的选项。
jQuery(document).ready(function($){
var selectEvent = function($el){
$(".selectmenu").change(function() {
var selectedValue = $("select.selectmenu").val();
alert('Selected event' + selectEvent);
});
};
$(".selectmenu").scrollectBox({
preset: 'dropdown',
numVisibleOptions: 4,
scrollInterval: 150,
scrollOn: 'hover',
listWidth: 160,
onSelectEvent: selectEvent
});
});
代码可能有误,但我怎样才能正确编写类似的语法。
感谢,
修改
插件网址:
https://github.com/afEkenholm/ScrollectBox
https://github.com/afEkenholm/ScrollectBox/blob/master/index.html
https://github.com/afEkenholm/ScrollectBox/blob/master/js/ScrollectBox/jquery.scrollectbox.js
<div id = "translate">
<select onchange="Translate(this)" name="select" id="translator" class="selectmenu" >
<option value="Select Language">Select Language</option>
<option value="en|af">Afrikaans</option>
<option value="en|sq">Albanian</option>
</select>
</div>
答案 0 :(得分:1)
试试这个:
var selectEvent = function($el){
console.log($el);
var selectedValue = $el.html();
alert(selectedValue);return false;
};
或者,如果您想要change event
,请尝试
var selectEvent = function($el){
console.log($el);
$el.change(function() {
var selectedValue = $(this).html();
alert('Selected value' + selectedValue);// I think its value not event
});
};