2 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
您onchange可以像這樣在選擇輸入上使用事件來做到這一點(diǎn):
<select onchange="changed(this)"></select>
function changed(option){
console.log(option.value);
}
這是一個(gè)工作片段
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貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊
你會(huì)這樣去做
document.querySelector('nav__div__one__dropdown').addEventListner('change',(e)=>{
const userId=e.target.value;
//here do your user tying logic
})
添加回答
舉報(bào)