after()与insertAfter()实例
来源:互联网 发布:知乎 app交互设计分析 编辑:程序博客网 时间:2024/06/08 00:34
在jquery中,after()与insertAfter()函数有着相同的功能,能够完成相同的任务,即添加文本或者html内容到匹配元素的后面,其主要的区别在于语法上的区别。
例如:
<divclass="greyBox">I'm a ipman</div>
<divclass="greyBox">I'm a ipman 2</div>
1. $(‘selector’).after(‘new content’);
$('.greyBox').after("<divclass='redBox'>Iron man</div>");
2. $(‘newcontent’).insertAfter(‘selector’);
$("<divclass='redBox'>Iron man</div>").insertAfter('.greyBox');
结果如下:
<divclass="greyBox">
I'm a ipman
</div>
<divclass='redBox'>Iron man</div>
<divclass="greyBox">
I'm a ipman 2
</div>
<divclass='redBox'>Iron man</div>
具体实例代码:
<html><head><script type="text/javascript" src="../jquery-1.11.1.min.js"></script><style type="text/css">.greBox{padding:8px;background:grep;margin-bottom:8px;width:300px;height:100px;}.redBox{padding:8px;background:red;margin-bottom:8px;width:300px;height:100px;}</style></head><body><h1>jquery after()andinsertAfter() example </h1><div class="greyBox">ip man</div><div class="greyBox">ip man2</div><p><button id="after">after()</button><button id="insertAfter">insertAfter()</button><button id="reset">reset</button></p><script type="text/javascript">$("#after").click(function(){$('.greyBox').after('<div class="redBox">iron man</div>');});$("#insertAfter").click(function(){$('<div class="redBox">iron man</div>').insertAfter('.greyBox');});$("#reset").click(function(){location.reload();});</script></body></html>
效果:
0 0
- after()与insertAfter()实例
- jquery的after与insertAfter的区别
- jQuery中append、insertBefore、after与insertAfter方法注意事项
- jquery中after与insertAfter有什么区别
- jQuery中append、insertBefore、after与insertAfter方法注意事项
- jQuery中append、appendTo、prepend、prependTo、before、insertBefore、after与insertAfter方法总结
- insertAfter
- javascript 基础 insertAfter与insertBefore
- WPF 之InsertBefore 与 InsertAfter用
- jquery DOM外部插入insertAfter()与insertBefore()
- DOM外部插入insertAfter()与insertBefore()
- JQuery中html、append、appendTo、after、insertAfter、before、insertBefore、empty、remove系列方法的使用。
- JQuery中html、append、appendTo、after、insertAfter、before、insertBefore、empty、remove系列方法的使用。
- jquery append appendTo before after insertAfter insertBefore prepend prependTo用法区别
- JQuery中html、append、appendTo、after、insertAfter、before、insertBefore、empty、remove系列方法的使用
- JQuery中html、append、appendTo、after、insertAfter、before、insertBefore、empty、remove系列方法的使用。
- js追加元素的几种方法(append()、prepend()、after()、before()、insertAfter()、insertBefore())
- JQuery中html、append、appendTo、after、insertAfter、before、insertBefore、empty、remove的使用
- 【Linux】(三)帮助 广播 解压缩
- 高数,原来可以这么诗意
- html表单
- POJ 1651 Multiplication Puzzle(区间dp)
- HDU 1978-How many ways(记忆化搜索)
- after()与insertAfter()实例
- 嵌入式之---常用模板函数(用法说明函数、参数解析函数)
- 数据结构与算法分析(C++)阅读笔记(1)
- 我的c++之路-MFC计算器的实现
- codeforces 176 B. Word Cut(DP)
- c17
- HDU1035深搜
- (一)策略模式
- iOS 判断gif图