无法更改具有自定义选择事件处理程序的选择菜单的选项

问题描述:

在以下调用函数中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 
    }); 
}); 

该代码可能是错误的,但我该如何正确编写类似的语法。

感谢,

编辑:

插件的url:

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> 

试试这个:

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 
    }); 
}; 
+0

代码不幸的是1块不能提取价值。它提醒空白弹出。第二块代码使选项不可点击。感谢, – 2013-03-25 16:47:45

+0

首先检查你是否通过'console.log($ el);'获得'element'并将'val()'改为'html()'。检查上面的答案我改变了它。 – 2013-03-26 04:26:44

+0

第一个代码块返回选项文本'Afrikaans',但不是实际选项值'en | af'。我编辑了我的问题。插件链接包含在我编辑的问题中。 – 2013-03-26 10:51:07