jquery操作文本代码值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="box"></div>
    <input type="text" id="username">
    <script src="lib/jquery-2.2.2.js"></script>
    <script>
        // html(s)设置html里面的内容
        $('#box').html('hello');
        //html()获取html里面的内容
        console.log($('#box').html());
         //text()设置文本内容
         $('#box').text('haha');
        //text(s)获取文本内容
        console.log($('#box').text());
        // val(s)设置value的值
          $('#username').val('xiaoming');
        //val()获取value的值
        console.log($('#username').val());
    </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44606660/article/details/88068407
今日推荐