jQuery不会在我的无序列表之后插入 [英] jquery won't insert after my unordered list
问题描述
我有一个无序列表(ul),我想在(ul)之前和之后插入一些标签.似乎可以在(ul)之前插入我的标签,但是由于某种原因,它不会在之后插入.这是jsfiddle: http://jsfiddle.net/grem28/ptSVA/1/ >
I have an unordered list (ul) that i'm trying to insert some tags before and after the (ul). It seems to insert my tags just fine before the (ul), but for some reason, it won't insert it after. Here's the jsfiddle: http://jsfiddle.net/grem28/ptSVA/1/
$('.isNav').addClass('nav').before('<nav class="navbar navbar-inverse"><div class="navbar-inner">').after('</div></nav>');
如果您检查结果,您会发现我在说什么.最初,我将它链接起来,但是它似乎将前后插入在一起,这就是为什么我将其分开.我以为如果我先做.after之后,那么.before会正确显示,但是不起作用.非常感谢您的所有帮助!
If you inspect the results you'll see what i'm talking about. Originally i had it chained, but it seemed to insert the before and after together and that is why i seperated it. I thought if i did the .after first then the .before it would show up correctly but it doesn't work. All your help is greatly appreciated!
谢谢
推荐答案
您必须使用wrap()
. before()
和after()
不会添加传递给函数的实际HTML,它们会添加带有结束标记的整个元素.因此,用before()
添加的元素会自动关闭,并且以后没有after()
函数关闭.
You have to use wrap()
. before()
and after()
do not add the actual HTML you pass to the function, they add the whole elements with closing tags. So the elements you added with before()
were automatically closed and there are no "open" tags afterwards to be closed with your after()
function.
使用wrap
的示例:
$('.isNav').addClass('nav').wrap('<nav class="navbar navbar-inverse"><div class="navbar-inner">');
这篇关于jQuery不会在我的无序列表之后插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!