3-3 编程练习:jQuery键盘事件案例

3-3 编程练习

完善下面的代码,在input框中输入内容的时候同样显示在下面的p标签中

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>习题</title>
</head>

<body>
    <input type="text" value="">
    <p></p>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script>
    //此处写代码
    </script>
</body>

</html>

 

任务

1、选中input元素

2、使用键盘事件,将input框中的内容添加到p标签中

任务提示

val()方法返回或者设置被选元素的值,获取输入框中的内容可以使用val()

参考代码

$($).ready(function () {
    $('input').keyup(function () {
        $('p').text($('input').val());
    })
})
View Code

 

posted @ 2019-06-13 12:30  请叫我二狗哥  阅读(247)  评论(0编辑  收藏  举报