标签:
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";
}
#div {
width: 200px;
height: 200px;
border: 1px red solid;
}
.test {
background: #76DBA3;
}
</style>
<script type="text/javascript" src="js/jquery-2.2.2.min.js">
</script>
<script type="text/javascript">
$(function () {
$("<div>", {
text: "这是动态创建的页面元素",
id: "div",
click: function () {
$(this).toggleClass("test");
}
}).appendTo("body");
})
</script>
</head>
<body>
</body>
</html>
result:
运行:
标签:
原文地址:http://www.cnblogs.com/theWayToAce/p/5495658.html