就是说,span里面的内容要随着input的变化而变化,两个标签都没有绑定事件,那就只能在js里面写了。
相关的知识点:
https://www.w3school.com.cn/js/js_htmldom_events.asp
<!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>JS4 单向绑定 </title>
</head>
<body>
<input id="input" type="text"/>
<span id="span"></span>
<script type="text/javascript">
// 补全代码
let inputNode=document.getElementById('input');
let spanNode=document.getElementById('span');
input.onchange=function(){
// console.log(this);
// console.log(this.value);
// console.log(event.target.value);
span.innerHTML=this.value;
}
</script>
</body>
</html>