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()); }) })
 
                     
                    
                 
                    
                
 

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号