html 与text 的区别?

来源:2-11 编程练习

慕设计916995

2020-07-28 19:01:25

<!DOCTYPE html>

<html>


<head>

    <meta charset="UTF-8">

    <title>习题</title>

    <style>

    div {

        width: 300px;

        height: 200px;

        overflow: scroll;

    }

    </style>

</head>


<body>

    <p>请试着滚动 DIV 中的文本:</p>

    <div>慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂

        <br /><br />

        慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂

        <br /><br />

        慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂

        <br /><br />

        慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂 慕课网-程序员的梦工厂

    </div>

    <p>滚动了 <span>0</span> 次。</p>

    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>

    <script>

    //此处写代码

    $(document).ready(function(){

        var content = 0;

        $('div').scroll(function(){

            content+=1;

            $('span').text(content);

            // $('span').html(content);

        });

    });

    </script>

</body>


</html>


写回答

1回答

好帮手慕久久

2020-07-29

同学你好,代码正确,问题解答如下:

“text”用来设置或者获取元素的文本内容,而html方法用来设置或返回被选元素的内容,包括标签,如下:

text:

http://img.mukewang.com/climg/5f20d3a109d418bb09740281.jpg

http://img.mukewang.com/climg/5f20d38f094ef72103220107.jpg

html:

http://img.mukewang.com/climg/5f20d39909e3a89f13100289.jpghttp://img.mukewang.com/climg/5f20d39c091ba14004160184.jpg

如果我的回答帮到了你,欢迎采纳,祝学习愉快!


0

0 学习 · 14456 问题

查看课程