简体   繁体   English

如何将其发送给onchange函数以进行选择?

[英]How can I send this to an onchange function for a select?

I have a select element and I want to set the onchange function and send 'this', I've tried these: 我有一个select元素,我想设置onchange函数并发送“ this”,我已经尝试了以下方法:

s.onchange= function() {console.log(this.selectedIndex);};

s.addEventListener('click', myFunction.bind(s), false);

But no luck, I'm still getting 'undefined'. 但是没有运气,我仍然变得“不确定”。 What is this still showing undefined even if I am binding? 即使绑定,这仍然显示未定义的内容吗?

Im not sure why you'd want to send this over event , but the following should be close to what you're looking for? 我不确定为什么要发送this over event ,但是以下内容应该与您要查找的内容接近?

var select = document.getElementById('select')

select.addEventListener('change', function(event) {
  readSelection(this)
})

function readSelection(input) {
  console.log(input)
}

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

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