jQuery 附加到列表底部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6334628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery append to bottom of list
提问by Kmack
Can someone lend me a hand
有人可以帮我一把吗
I have this unordered list
我有这个无序列表
<ul id="nav">
<li><a href="whatwedo.aspx">WHAT WE DO</a>
<ul>
<li><a href="development.aspx">Development</a></li>
<li><a href="marketassessment.aspx">MARKET ASSESSMENT AND CONCEPT DEVELOPMENT</a></li>
<li><a href="planning.aspx">DEVELOPMENT PLANNING AND OVERSIGHT</a></li>
<li><a href="preopening.aspx">PRE-OPENING OPERATIONAL SERVICES</a></li>
<li><a href="operations.aspx">OPERATIONAL MANAGEMENT SERVICES</a></li>
<li><a href="turnaround.aspx">TURNAROUND SERVICES</a></li>
<li><a href="news.aspx">NEWS</a></li>
</ul>
</li>
<li><a href="ourparks.aspx">OUR PARKS</a></li>
<li><a href="contact.aspx">CONTACT US</a></li> </ul>
And I want to add a new list to the bottom of the list.
我想在列表底部添加一个新列表。
<li class="last_link"><a href="https://projects.parc-services.com" target="blank">Login</a></li>
Would I go about it by doing something like this?
我会做这样的事情吗?
$("#nav ul").prepend("<li></li>");
回答by Darin Dimitrov
If you want to add at the end use the append()
method instead of prepend()
:
如果要在最后添加,请使用该append()
方法而不是prepend()
:
$('#nav ul').append('<li class="last_link"><a href="https://projects.parc-services.com" target="blank">Login</a></li>');
or as I prefer:
或者我更喜欢:
$('#nav ul').append(
$('<li/>', {
'class': 'last_link',
html: $('<a/>', {
href: 'https://projects.parc-services.com',
target: '_blank',
text: 'Login'
})
})
);
回答by Romain Guidoux
prepend
adds something at the beginning of an element.
append
is used to add something at the end.
prepend
在元素的开头添加一些东西。
append
用于在最后添加一些东西。
$("#nav ul").append($("<li></li>").html('something'));
And if you want to add a class, or anything else you can:
如果你想添加一个类或其他任何东西,你可以:
$("#nav ul").append($("<li></li>").html('something')
.addClass('myclass'));