[英]How do I use jQuery to insert an li between two other li's when they contain siblings?
I'm trying to add a list item (Your Information) between two other list items (FirstName and Email), but have been unsuccessful because the two list items contain siblings. 我正在尝试在其他两个列表项(名字和电子邮件)之间添加一个列表项(您的信息),但是由于两个列表项包含同级项而没有成功。 Thanks for your help!
谢谢你的帮助!
<script type="text/javascript">
$(document).ready(function(){
$('<li>Your Information</li>').insertAfter('#FirstName');
});
</script>
<form class="lpeRegForm"><ul class='mktLblLeft'>
<li class='Field' >
<label>First Name:</label>
<span class='Input'>
<input class='FormText' name="FirstName" id="FirstName" type='text' value="" maxlength='255' tabIndex='1' />
<span class='FormMsg'></span>
</span>
</li>
<li class='Field' >
<label>Email Address:</label>
<span class='Input'>
<input class='FormText' name="Email" id="Email" type='text' value="" maxlength='255' tabIndex='2' />
<span class='FormMsg'></span>
</span>
</li>
</ul>
</form>
You need to insert it after the li
that #FirstName
is inside of. 您需要在
#FirstName
位于其中的li
之后插入它。 Eg, 例如,
$('<li>Your Information</li>').insertAfter($('#FirstName').closest('li'));
$('#FirstName').closest('li').after('<li>Your Information</li>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.