Javascript 从OL中删除LI元素
我知道下面的代码可以删除数组中的第一个子元素,但是如果我想按元素在数组中的顺序指定元素,那么代码是什么呢?e、 g.我的OL有5个LI元素,我想删除第三个元素[2] jQuerywords li:first-child.remove; 你好 再见 jQuerywords li:nth-child2.remove//注意它从1开始 你好 再见 您可以使用jQuery:nth child或:eq选择器来执行作业 :n子选择器 索引:要匹配的每个子级的索引, 从1开始,字符串为偶数或奇数,或一个等式如。 :n儿童偶数,:n-child4n :均衡器选择器 索引:要匹配的元素的从零开始的索引 例如—Javascript 从OL中删除LI元素,javascript,jquery,Javascript,Jquery,我知道下面的代码可以删除数组中的第一个子元素,但是如果我想按元素在数组中的顺序指定元素,那么代码是什么呢?e、 g.我的OL有5个LI元素,我想删除第三个元素[2] jQuerywords li:first-child.remove; 你好 再见 jQuerywords li:nth-child2.remove//注意它从1开始 你好 再见 您可以使用jQuery:nth child或:eq选择器来执行作业 :n子选择器 索引:要匹配的每个子级的索引, 从1开始,字符串为偶数或奇数,或一个等
<script type="text/javascript">
function removeChild(index) {
// :nth-child() Selector
// index: The index of each child to match, starting with 1.
$('ol li:nth-child(' + index + ')').remove();
// Using :eq() Selector
// index: Zero-based index of the element to match.
$('ol li:eq(' + index + ')').remove();
}
</script>
测验
功能点击删除{
$'words li'.eqint.remove;
变量a=$'button'。长度-1;
$‘按钮’.eqa.remove;
}
你好
再见
罗莫夫1
罗莫夫2
您可以使用li:eq1选择器。谢谢,我使用了$'words li:eq0'。删除;这就成功了:-