event.target.value
时间: 2023-09-08 19:14:12 浏览: 82
js中的触发事件对象event.srcElement与event.target详解
event.target.value is a property of the event object in JavaScript. It is used to retrieve the current value of the target element that triggered the event.
For example, if you have an input element with the id "myInput", and you want to retrieve its current value when it changes, you can use the following code:
```
document.getElementById("myInput").addEventListener("input", function(event) {
console.log(event.target.value);
});
```
In this code, we are adding an event listener to the input element that listens for the "input" event. When the input value is changed, the event object is passed to the callback function, and we can access the current value of the input element using event.target.value.
阅读全文