<!DOCTYPE?html>
<html>
<head>
????<meta?http-equiv="Content-type"?content="text/html;?charset=utf-8"?/>
????<title></title>
????<script?src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
????<style>
????.left,
????.right?{
????????width:?250px;
????????height:?130px;
????????background-color:red;//問題地點(diǎn)
????}
????
????.left?div,
????.right?div?{
????????width:?100px;
????????padding:?5px;
????????margin:?5px;
????????float:?left;
????????border:?1px?solid?#ccc;
????????background:?#bbffaa;
????}
????
????.right?div?{
????????background:?yellow;
????}
????p?{
????????border:?1px?solid?red;
????}
????
????a?{
????????border:?1px?solid?blue;
????}
????</style>
</head>
<body>
????<h2>DOM包裹wrapInner()方法</h2>
????<div?class="left">
????????<div?class="aaron1">點(diǎn)擊,通過wrapInner方法給所有P元素增加內(nèi)部父容器div</div>
????????<div?class="aaron2">點(diǎn)擊,通過wrapInner的回調(diào)方法給每個a元素增加內(nèi)部父容器div</div>
????</div>
????<div?class="right">
????????<p>p元素</p>
????????<p>p元素</p>
????</div>
????<div?class="left">
????????<a>a元素</a>
????????<a>a元素</a>
????</div>
????<script?type="text/javascript">
????$(".aaron1").on('click',?function()?{
????????//給所有p元素,增加內(nèi)部包裹父容器div
???????$('p').wrapInner('<div></div>');
????})
????</script>
????<script?type="text/javascript">
????$(".aaron2").on('click',?function()?{
????????//wrapInner接受一個回調(diào)函數(shù)
????????//每一次遍歷this都指向了合集中每一個a元素
????????$('a').wrapInner(function()?{
????????????return?'<div></div>'
????????})
????})
????</script>
</body>
</html>
2017-01-03
我覺得是增加的這個P元素的外邊距把盒子撐開了,把P的margin設(shè)置為0,這樣就不會撐開了。
2016-10-22
.right?{
????????width:?250px;
????????height:?130px;
????????background-color:red;//問題地點(diǎn)
????}
在這個代碼中加一行距頂部10像素