繁体   English   中英

如何添加onchange事件以选择标记并使select标签也有使用mithril.js的选项兄弟

[英]How to add an onchange event to select tag and have the select tag also have option siblings using mithril.js

我不知道如何向元素添加事件和兄弟元素。

我现在拥有的例子:

m('select', [
  ctrl.countries().map(function(d, i){ 
    return m('option', { onclick : ctrl.country_add.bind(group, group.countries),  value : d.iso2, innerHTML : d.Name })
    console.log(d,i);
  })
])

以及我认为可以工作但却没有的例子。

m('select', { onchange : function(){alert('this')}},[-
  ctrl.countries().map(function(d, i){ 
    return m('option', { value : d.iso2, innerHTML : d.Name })
    console.log(d,i);
  })
])

我希望它清楚我的意图是什么。 请注意,onclick事件在示例2中被删除,并且onchange事件被添加到其父元素“select”中。

第二个片段工作正常吗?

m.render(document.body, [

m('select', { onchange : function(){ alert('this') }},[
  [1, 2, 3].map(function(d, i){ 
    return m('option', { value : d, innerHTML : d })

  })
])

]
);

http://jsfiddle.net/3eshvafc/

暂无
暂无

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

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