到底什么時候加$
$("#bt2").on('click', function() {
? ? ? ? //在test2元素前后插入集合中每個匹配的元素
? ? ? ? //不支持多參數
? ? ? $('<p style="color:red">測試insertAfter方法增加</p>', '<p style="color:red">多參數</p>').insertAfter($(".test2"))?
? ? ?('.test2').after('<p>你好我在后面加入</p>','<p>哈哈哈</p>')
? ? })
為什么我用after方法就不用加$,也可以實現,而insertBefore中插入必須要用$()
2019-07-18
after的前面選擇器要加$,后面要加的內容是HTML,不需要$。
2018-09-07
其實都要加的,你看看前面章節的選擇器,表示選擇器的都有$