zoukankan      html  css  js  c++  java
  • jquery HTML--获取(text(), html(), val() 获取内容 )

    三个简单实用的用于DOM操作jQuery方法,我个人老是容易记混:

    test():设置或返回所选元素的文本内容

    html():设置或返回所选元素的内容(包括HTML标记)

    val():设置或返回表单字符段的值(input标签中的值)

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
        <script src="jquery/jquery-3.3.1.min.js"></script>
        <script>
            $(
                    function(){
                        $("#btn0").click(
                                function(){
                                    alert($("#div1").text());
                                    alert($("#div2").text());
                                    alert($("#div1").html());
                                    alert($("#div2").html());
                                    alert($("input").val());
                                }
                        )

                    }
            )
            $(
                    function(){
                        $("#btn1").click(
                                function(){
                                    $("#div1").text("<b>初终</b>");
                                    $("#div2").text("初心");
                                }
                        )

                    }
            )
            $(
                    function(){
                        $("#btn2").click(
                                function(){
                                    $("#div1").html("<b>初终</b>");
                                    $("#div2").html("初心");
                                }
                        )

                    }
            )
            $(
                    function(){
                        $("#btn3").click(
                                function(){
                                    $("input").val("左右");
                                }
                        )

                    }
            )
        </script>
    </head>
    <body>
        <div id="div1" style=" border:1px solid gray ; 150px; height: 30px">
            从未
        </div>
        <hr>
        <div id="div2" style="border:1px solid gray ; 150px; height: 30px">
            左右
        </div>
        <hr>
            <input type="text" value="昔日">
        <hr>
        <div>
            <button type="button" id="btn0">获取内容</button>
            <button type="button" id="btn1">改变text内容</button>
            <button type="button" id="btn2">改变html内容</button>
            <button type="button" id="btn3">改变value内容</button>
        </div>


    </body>
    </html>
    ---------------------
    作者:一心不安
    来源:CSDN
    原文:https://blog.csdn.net/qq_42700595/article/details/84541112
    版权声明:本文为博主原创文章,转载请附上博文链接!

    我是代码搬运工!!!
  • 相关阅读:
    delphi 多线程定时执行程序如何写
    delphi 把多个线程的请求阻塞到另一个线程 TElegantThread
    delphi 对TThread扩充TSimpleThread
    Delphi 线程Timer (TThreadTimer)
    vue-01-插值表达式、事件修饰符
    ORA-12516:监听程序找不到服务协议堆栈要求的可用处理程序(转)
    Io 异常: The Network Adapter could not establish the connection(转)
    "Cannot read property 'xxx' of undefined" js问题之某属性未定义
    数据库用日期作为条件来查询数据
    Docker Registry配置客户端
  • 原文地址:https://www.cnblogs.com/FanKL/p/10988352.html
Copyright © 2011-2022 走看看