jQuery不会在我的无序列表之后插入 [英] jquery won't insert after my unordered list

查看:80
本文介绍了jQuery不会在我的无序列表之后插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无序列表(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的示例:

http://jsfiddle.net/ptSVA/2/

$('.isNav').addClass('nav').wrap('<nav class="navbar navbar-inverse"><div class="navbar-inner">');

这篇关于jQuery不会在我的无序列表之后插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆