<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" id="ipt" value="" oninput="changeData(this.value)">
<h2 id="title"></h2>
<script>
var data = {};
var title = document.getElementById("title");
var ipt = document.getElementById("ipt");
Object.defineProperty(data, "msg", {
get: function(){
return "你好世界"
},
set: function(newValue){
title.innerHTML = newValue;
txt.value = newValue;
}
})
title.innerHTML = data.msg;
ipt.value = data.msg;
function changeData(value){
data.msg = value;
}
</script>
</body>
</html>