zoukankan      html  css  js  c++  java
  • jQuery HTML 操作 改变/添加文本值

    1、JQuery 改变p中的文本值

    <html>
    <head>
    <script type="text/javascript" src="jquery-1.7.1.min.js"></script> 
    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
      $("p").html("Update text");
      });
    });
    </script>
    </head>
    
    <body>
    <h2>This is a heading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button type="button">Click here</button>
    </body>
    
    </html>
    

     2、JQuery 添加p中的文本值

    <html>
    <head>
    <script type="text/javascript" src="jquery-1.7.1.min.js"></script> 
    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
      $("p").append(" Append text");
      });
    });
    </script>
    </head>
    
    <body>
    <h2>This is a heading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button type="button">请点击这里</button>
    </body>
    
    </html>
    

     3、after() 函数在所有匹配的元素之后插入 HTML 内容

    <html>
    <head>
    <script type="text/javascript" src="jquery-1.7.1.min.js"></script> 
    
    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
      $("p").after(" Add  content.");
      });
    });
    </script>
    </head>
    
    <body>
    <h2>This is a heading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button type="button">Click here</button>
    </body>
    
    </html>
    

     4、jQuery HTML 操作

    函数描述
    $(selector).html(content) 改变被选元素的(内部)HTML
    $(selector).append(content) 向被选元素的(内部)HTML 追加内容
    $(selector).prepend(content) 向被选元素的(内部)HTML “预置”(Prepend)内容
    $(selector).after(content) 在被选元素之后添加 HTML
    $(selector).before(content) 在被选元素之前添加 HTML
  • 相关阅读:
    (005)Linux 复制命令cp总提示是否覆盖的解决方法,在cp前加
    (030)Spring Boot之RestTemplate访问web服务案例
    Gym
    Gym
    Gym.102006:Syrian Collegiate Programming Contest(寒假自训第11场)
    BZOJ-5244 最大真因数(min25筛)
    HDU
    HDU 1272 小希的迷宫(并查集)
    HDU 3038 How Many Answers Are Wrong(带权并查集)
    POJ 1182 食物链(带权并查集)
  • 原文地址:https://www.cnblogs.com/linlf03/p/2309666.html
Copyright © 2011-2022 走看看