动态插入节点

HTML:
<!DOCTYPE >

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style type="text/css">
* {
margin: 10px;
padding: 0;
font-family: "微软雅黑", "arial", " sans-serif";
font-size: 14px;
}

button {
width: 120px;
height: 33px;
border-radius: 5px;
color: snow;
background: #5CA113;
font-weight: bold;
}

#ul li {
display: inline;
}
</style>
<script type="text/javascript" src="js/jquery-2.2.2.min.js">
</script>

<script type="text/javascript">
$(function () {
$("#append").click(function () {
$("#content").append("<b>使用append添加元素</b>")
});
$("#appendTo").click(function () {
$("<b>使用appendTo添加元素</b>").appendTo("#content");
});
$("#prepend").click(function () {
$("#content").prepend("<b>使用prepend插入前置内容</b>")
});
$("#prependTo").click(function () {
$("<b>使用prependTo插入前置内容</b>").prependTo("#content");
});
$("#before").click(function () {
$("#content").before("<b>使用before添加元素</b>")
});
$("#after").click(function () {
$("#content").after("<b>使用after添加元素</b>")
});
$("#insertBefore").click(function () {
$("<b>使用inserBefore添加元素</b>").insertBefore("#content");
});
$("#insertAfter").click(function () {
$("<b>使用insertAfter添加元素</b>").insertAfter("#content");
});
})
</script>
</head>

<body>
<ul id="ul">
<li>
<button id="append">append方法</button>
</li>
<li>
<button id="appendTo">appendTo方法</button>
</li>
<li>
<button id="prepend">prepend方法</button>
</li>
<li>
<button id="prependTo">prependTo方法</button>
</li>
<li>
<button id="before">before方法</button>
</li>
<li>
<button id="after">after方法</button>
</li>
<li>
<button id="insertBefore">insertBefore方法</button>
</li>
<li>
<button id="insertAfter">insertAfter方法</button>
</li>

</ul>
<div id="content" style="width: 580px;height: 160px;border: 1px red solid;font-size: 16px;color: red;"><p
style="color: black;font-size: 18px;"> 使用不同的按钮,用不同的方法插入页面</p></div>
</body>

</html>
result:


运行:



 

转载于:https://www.cnblogs.com/theWayToAce/p/5495747.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值