zoukankan      html  css  js  c++  java
  • jquery append()方法与html()方法使用方法差别

    append(content):方法在被选元素的结尾(仍然在内部)插入指定内容,有非常多朋友认为append与html差点儿相同。其他从英文意义上append是在原有基础上添加,而html中是替换当前全部内容。
    定义和使用方法
    append() 方法在被选元素的结尾(仍然在内部)插入指定内容。


    $(selector).append(content)
    使用函数来附加内容
    使用函数在指定元素的结尾插入内容。


    语法

    $(selector).append(function(index,html))

    实例代码:

    <script src="/jquery.min.js" type="text/javascript"></script>
    <style>
    .imgFocus{border: 1px solid #eee;}
    </style>
    <p> </p>
    <script type="text/javascript">
    var showimg = "<div class='imgFocus'>123456</div>";
    $("p").append(showimg);
    </script>

    html() 方法返回或设置被选元素的内容 (inner HTML)。

    假设该方法未设置參数。则返回被选元素的当前内容。


    返回元素内容
    当使用该方法返回一个值时。它会返回第一个匹配元素的内容。

    语法

    $(selector).html()


    设置全部 p 元素的内容:

    $(".btn1").click(function(){
      $("p").html("Hello <b>world</b>!");
    });

    指定元素中清空

    $("a[href$='logout.asp']").click(function(event) {
      event.preventDefault();
        $.get("/xxlr/Logout.asp","",function(data, textStatus) {
        if (data == 1) {  //表明注销成功
            $('#message').html("");
            $("#userlogin>div").show(); 
        }
        else {
            $('#message').append("<p><strong>注销失败,请又一次尝试!</strong></p>");
        }
        });
    }); 


  • 相关阅读:
    TYPE_SCROLL_INSENSITIVE is not compatible with CONCUR_UPDATABLE
    with admin option /with grant option
    通过动态SQL语句创建游标
    Vue:在vue-cli中使用Bootstrap
    Vue:$set和$delete
    Vue:如何在vue-cli中创建并引入自定义组件
    MVC教程四:Controller向View传值的几种方式
    Vue:生命周期
    Vue.js常用指令:v-model
    vue:过滤器
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/8412213.html
Copyright © 2011-2022 走看看