题解 | #单向绑定#

单向绑定

http://www.nowcoder.com/practice/728b83e2b9b948dbababcc4a494eefc3

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8>
    </head>
    <body>
    	<input id="input" type="text" />
        <span id="span"></span>

        <script type="text/javascript">
            document.getElementById("input").onchange = function(){
                // dom事件里的函数的this指向触发者,即input标签
                // 注意:这里不能使用箭头函数,因为箭头函数没有this指针,箭头函数的this是根据执行上下文确定的,即这里的this指向window,会报错
                document.getElementById("span").innerHTML = this.value
            }
        </script>
    </body>
</html>
全部评论

相关推荐

迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
评论
17
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务