怎么得到已经获取焦点的input框的值知道输入框获得了焦点,怎么通过他的焦点得到该输入框的值呢
1 回答
幕布斯7119047
TA贡献1794条经验 获得超8个赞
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title></head><body> <input type="text" value="输入字段12"> <input type="text" value="输入字段34"> <button>按钮</button></body><script> window.onload = function () { let input = document.getElementsByTagName('input'); for (let i = 0; i < input.length; i++) { input[i].addEventListener('focus', (e) => { console.log(e.target.value); }) } }</script></html>
添加回答
举报
0/150
提交
取消