我想首先添加元素,如下所示.我怎样才能做到这一点 ?
$('<li>').appendTo($('ul')); // add it as last element
<ul>
<!-- i want to add element here -->
<li></li>
<li></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
使用jQuery的.prepend()http://api.jquery.com/prepend/
$('ul').prepend('<li>new</li>')
Run Code Online (Sandbox Code Playgroud)