Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从OL中删除LI元素_Javascript_Jquery - Fatal编程技术网

Javascript 从OL中删除LI元素

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开始,字符串为偶数或奇数,或一个等

我知道下面的代码可以删除数组中的第一个子元素,但是如果我想按元素在数组中的顺序指定元素,那么代码是什么呢?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

:均衡器选择器

索引:要匹配的元素的从零开始的索引

例如—

<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'。删除;这就成功了:-