test

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<input type="text" id="inputtest" />
<span id="preview"></span>

<script>

    function getId(id){
        return document.getElementById(id);
    }

    var domInput = getId('inputtest');

    //这个不能及时更新
//    domInput.onkeypress = function () {
//        getId('preview').innerHTML = this.value;
//    }

    //这个能及时更新
//    domInput.onkeyup = function () {
//        getId('preview').innerHTML = this.value;
//    }

    domInput.onkeypress = function () {
        alert(1);
    }

</script>
</body>
</html>

 

你可能感兴趣的:(test)