移除方法:1、利用“eq(-1)”选择器和remove()方法,语法“$(Element).eq(-1).remove()”;2、利用“:last”选择器和remove()方法,语法“$(Element:last).remove()”。

本教程操作环境:windows7系统、jquery3.6.1版本、Dell G3电脑。
jquery从末尾移除一个元素
方法1:“eq(-1)”选择器+remove()方法
利用“eq(-1)”选择器从末尾选中最后一个元素
使用remove()方法删除选中的元素
html>
<meta><script></script><script>
$(document).ready(function() {
$("p").eq(-1).remove();
});
</script><p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
<p>第五段</p>
<p>第六段</p>

jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
方法2:“:last”选择器+remove()方法
利用“:last”选择器从末尾选中最后一个元素
使用remove()方法删除选中的元素
html>
<meta><script></script><script>
$(document).ready(function() {
$("p:last").remove();
});
</script><p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
<p>第五段</p>

相关教程推荐:jQuery视频教程










