2 回答
TA贡献1853条经验 获得超6个赞
您onchange可以像这样在选择输入上使用事件来做到这一点:
<select onchange="changed(this)"></select>
function changed(option){
console.log(option.value);
}
这是一个工作片段
let userInstantiation = [{id: 1, name: 'user1'},{id: 2, name: 'user2'}];
let userDropDownList = userInstantiation.reduce((usersHTML, user) =>
usersHTML +=
`<option class="nav__div__one__dropdown__choice" value="${user.id}">${user.name}</option>`
, '')
document.querySelector(".nav__div__one__dropdown").innerHTML = userDropDownList;
function changed(option){
console.log(option.value);
}
<select class="nav__div__one__dropdown" onchange="changed(this)" name="users"></select>
TA贡献1863条经验 获得超2个赞
你会这样去做
document.querySelector('nav__div__one__dropdown').addEventListner('change',(e)=>{
const userId=e.target.value;
//here do your user tying logic
})
添加回答
举报