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>
  • 相关阅读:
    [PyJs系列介绍]一、从commonjs和seajs说起
    [PyJs系列介绍]五、回顾及展望
    [PyJs系列介绍]三、编译与上线
    url decode problem
    [PyJs系列介绍]二、缘起和核心概念
    ControlJS介绍
    css,javascript的预加载
    [PyJs系列介绍]四、代理与插件
    webservice上传图片
    提高IIS7并发连接数
  • 原文地址:https://www.cnblogs.com/mysearchblog/p/5605571.html
Copyright © 2011-2022 走看看