zoukankan      html  css  js  c++  java
  • [ jquery 方法 text([val|fn]) ] 此方法操作匹配的元素或元素集中的内容,相当于javascript中的innerText属性

    取得所有匹配元素的内容:结果是由所有匹配元素包含的文本内容组合起来的文本,这个方法对HTML和XML文档都有效,相当于javascript中的innerText属性,可读可写,但是无法解析HTML标签:

    如果传入的是callback,此函数返回一个字符串并且参数解析如下:

      1.index为元素在集合中的索引位置

      2.text为原先的text值。

    实例:

    <!DOCTYPE html>
    <html lang='zh-cn'>
    <head>
    <title>Insert you title</title>
    <meta http-equiv='description' content='this is my page'>
    <meta http-equiv='keywords' content='keyword1,keyword2,keyword3'>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!-- <script type='text/javascript' src='./js/jquery-3.0.0.js'></script> -->
    <script type='text/javascript' src='./js/jquery-1.12.1.min.js'></script>
    <style type='text/css'>
       div{font:400 25px/250px 'Courier New';text-align:center;color:#000;border:1px solid #F50;700px;height:250px;margin:20px auto;}
       .addOne{padding:0 8px;}
       .addTwo{color:#999;}
    </style>
    <script type='text/javascript'>
        $(function(){
                alert($('#user').text());
               $('#user').text(function(index,oldText){
                   return oldText + '<strong>this is a test</strong>';
               });
        });
    </script>
    </head>
    <body>
       <div id='user' class='addOne addTwo'>oldChar</div>
    </body>
    </html>
  • 相关阅读:
    刚开始用springboot踩的好多坑!!!
    AngularJS学习(一)
    linux上的第一个c语言程序
    设计模式——6大设计原则
    C# List的深复制
    C# XML 操作
    C#多线程学习
    实现树形结构
    观察者模式
    python3.3 MD5
  • 原文地址:https://www.cnblogs.com/mysearchblog/p/5605571.html
Copyright © 2011-2022 走看看