移除方法: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()方法删除选中的元素
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="js/jquery-3.6.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("p").eq(-1).remove();
});
</script>
</head>
<body>
<p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
<p>第五段</p>
<p>第六段</p>
</body>
</html>
方法2:“:last”选择器+remove()方法
利用“:last”选择器从末尾选中最后一个元素
使用remove()方法删除选中的元素
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="js/jquery-3.6.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("p:last").remove();
});
</script>
</head>
<body>
<html>
<body>
<p>第一段</p>
<p>第二段</p>
<p>第三段</p>
<p>第四段</p>
<p>第五段</p>
</body>
</html>
</body>
</html>
相关教程推荐:jQuery视频教程
以上就是jquery怎么从末尾移除一个元素的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号