表单事件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单事件</title>
</head>
<body>
    <form action="">
        <input type="text" name="usr">
        <button type="submit">提交</button>
        <div></div>
    </form>
</body>
<script type="text/javascript">
    var form = document.querySelector(‘form‘)
    var ipt = document.querySelector(‘input‘)
    var btn = document.querySelector(‘button‘)
    ipt.onselect = function () {
        console.log(‘文本被选中‘);
    };
    var div = document.querySelector(‘div‘)
    // ipt.oninput = function () {
    //     console.log(‘值改变‘);
    //     div.innerText = this.value
    // };
    // ipt.onkeyup = function () {
    //     div.innerText = this.value
    // }
    // ipt.onchange = function () {
    //     div.innerText = this.value
    // }
    form.onsubmit = function () {
        console.log(‘提交‘)
        return false;
    }

</script>
</html>

相关推荐