let input = document.getElementById('testInput');
Object.defineProperty(input, 'value', {
configurable: true,
set: function(value) {
console.log('你设置了'+this+'的值为:'+value);
},
get: function() {
return '你访问了'+this;
}
});
console.log(input.value);
console.log(input.value=1);
<input type="text" id="testInput" />