.insertBefore( ) 為什么新加的內(nèi)容沒有背景顏色?新加的p標(biāo)簽不應(yīng)該在<div class = ' aaron' 里面嗎?
? ? <div class="aaron">
? ? ? ? <p class="test1">測試insertBefore,不支持多參數(shù)</p>
? ? </div>
? ? <script type="text/javascript">
? ? $("#bt1").on('click', function() {
? ? ? ? //在test1元素前后插入集合中每個(gè)匹配的元素
? ? ? ? //不支持多參數(shù)
? ? ? ? $('<p style="color:red">測試insertBefore方法增加</p>', '<p style="color:red">多參數(shù)</p>').insertBefore($(".test1")) ;
? ? })
2018-08-10
執(zhí)行完點(diǎn)擊事件后,p標(biāo)簽跟.test1是兄弟節(jié)點(diǎn)關(guān)系,只有.test1上有背景色,所以新加的內(nèi)容沒有背景顏色,你要是想讓新加的內(nèi)容有背景顏色,有兩種方式:
在.aaron上添加背景顏色
在p標(biāo)簽上加.test1 ,eg:
$('<p style="color:red"? class="test1">測試insertBefore方法增加</p>', '<p style="color:red">多參數(shù)</p>').insertBefore($(".test1")) ;
2018-08-09
可是它的樣式只有test的背景顏色啊...