jQuery 语义 UI 下拉更改处理程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20817669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Semantic UI dropdown change handler
提问by Ionic? Biz?u
I have the following dropdown using Semantic UI:
我有以下使用语义 UI 的下拉列表:
<div class="ui selection dropdown select-language">
<input name="language" type="hidden" value="fr-FR">
<div class="text">French</div>
<i class="dropdown icon"></i>
<div class="menu ui transition hidden">
<div class="item" data-value="en-US">English</div>
<div class="item active" data-value="fr-FR">French</div>
</div>
</div>
And in the jQuery side I init it:
在 jQuery 端我初始化它:
$(".select-language").dropdown()
How can I add the change
handler?
如何添加change
处理程序?
The only thing related to this I found in the documentationis:
我在文档中找到的唯一与此相关的 是:
onChange(value, text)
Context: Dropdown
Is called after a dropdown item is selected. receives the name and value of selection.
onChange(值,文本)
上下文:下拉
在选择下拉项后调用。接收选择的名称和值。
This sounds a little confusing for me. How can I use it?
这对我来说听起来有点混乱。我怎样才能使用它?
回答by Jan
Actually, there are three ways to bind the event:
实际上,绑定事件的方式有以下三种:
// globally inherited on init
$.fn.dropdown.onChange = function(){...};
// during init
$('.myDropdown').dropdown({
onChange: function() {...}
});
// after init
$('.myDropdown').dropdown('setting', 'onChange', function(){...});