Jquery学习之旅之添加元素
2016-04-18 01:40
661 查看
Jquery中的添加元素的方法有before(),after(),append(),prepend(),四种方法,before() 在指定元素的前面添加元素,after()在指定元素的后面添加元素,而append在指定元素的末尾添加元素,而prepend,在指定元素的开始处添加元素,下面是代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
*{
font-size:24px;
font-family: "微软雅黑";
}
.anii{width:100px;height:60px;background-color: red;position: absolute;}
</style>
</head>
<body>
<table>
<tr><th>one</th></tr>
</table>
<button id="append">append</button>
<button id="prepend">prepend</button>
<button id="before">before</button>
<button id="after">after</button>
<p>这是一个html</p>
<script type="text/javascript" src="jquery/jquery-2.1.1.js"></script>
<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$(document).ready(
function()
{
$("#append").click(function(){$("table").append("<tr><th>two</th></tr>");});
$("#prepend").click(function(){$("table").prepend("<tr><th>three</th></tr>");});
$("#before").click(function(){$("table").before("<h1>这是在元素前面添加的</h1>");});
$("#after").click(function(){$("table").after("<h1>这是在元素后面添加的</h1>");});
}
);
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
*{
font-size:24px;
font-family: "微软雅黑";
}
.anii{width:100px;height:60px;background-color: red;position: absolute;}
</style>
</head>
<body>
<table>
<tr><th>one</th></tr>
</table>
<button id="append">append</button>
<button id="prepend">prepend</button>
<button id="before">before</button>
<button id="after">after</button>
<p>这是一个html</p>
<script type="text/javascript" src="jquery/jquery-2.1.1.js"></script>
<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$(document).ready(
function()
{
$("#append").click(function(){$("table").append("<tr><th>two</th></tr>");});
$("#prepend").click(function(){$("table").prepend("<tr><th>three</th></tr>");});
$("#before").click(function(){$("table").before("<h1>这是在元素前面添加的</h1>");});
$("#after").click(function(){$("table").after("<h1>这是在元素后面添加的</h1>");});
}
);
</script>
</body>
</html>
相关文章推荐
- Jquery学习之旅之捕获和设置
- JQuery学习笔记——Ajax
- jquery中attr和prop的区别
- jQuery实现鼠标跟随提示层效果代码(可显示文本,Div,Table,Html等)
- jQuery validate+artdialog+jquery form实现弹出表单思路详解
- jQuery使用$.each遍历json数组的简单实现方法
- jQuery animate和CSS3相结合实现缓动追逐效果附源码下载
- jQuery 如何给Carousel插件添加新的功能
- 原生JS和jQuery版实现文件上传功能
- jQuery的内容过滤选择器学习教程
- 举例讲解jQuery中可见性过滤选择器的使用
- 简单讲解jQuery中的子元素过滤选择器
- 使用jquery.qrcode生成二维码
- 有什么开发工具写JavaScript和Jquery比较好?
- jquery 常用异步请求(ajax,post,get)和json对象的遍历
- jQuery 各种选择器 $.()用法
- jQuery的deferred对象详解
- 触碰jQuery:AJAX异步详解
- jquery 跨域 请求
- python 学习笔记十三 JQuery(进阶篇)