码迷,mamicode.com
首页 > Web开发 > 详细

【学亮IT手记】jQuery text()/html()回调函数实例

时间:2018-08-11 19:37:45      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:java   https   .com   实例   fun   段落   query   oct   dex   

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
 6 <script type="text/javascript">
 7     $(function(){
 8         $("#btn1").click(function(){
 9             $("#test1").text(function(i,oldVal){
10                 return "旧文本:"+oldVal+" 新文本:你我他学习吧(index:"+i+")";
11             })
12         })
13         $("#btn2").click(function(){
14             $("#test2").html(function(i,oldHtml){
15                 return "旧html:"+oldHtml+" 新html:你我他<b>学习吧</b>(index:"+i+")";
16             })
17         })
18     })
19 </script>
20 </head>
21 
22 <body>
23     <p id="test1">这是段落中的<b>粗体</b>文本。</p>
24     <p id="test2">这是另一个有<b>粗体</b>字的段落。</p>
25     <button id="btn1">显示 新/旧 文本</button>
26     <button id="btn2">显示 新/旧 HTML</button>
27 </body>
28 </html>

 

【学亮IT手记】jQuery text()/html()回调函数实例

标签:java   https   .com   实例   fun   段落   query   oct   dex   

原文地址:https://www.cnblogs.com/niwotaxuexiba/p/9460658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!