jquery - jQuery - Remove last item of multiple selects that starts with same ID
问题描述
I have a table that has multiple rows. This table has in a column a SELECT
that starts with ID=next_(rowindex)
What I need is when I button clicks the event to remove the last option of each SELECT
.
I'm doing this right now but is not working because is removing the last option of the last SELECT.
$("select[id^='next_'] option").last().remove();
And what I need is that all SELECT elements have the same items, so each one gets the last item removed.
Any clue?
解决方案
要删除多选的最后一个选项,请使用以下代码:
$("select[id^='next_'] option:last-child").remove();
它将选择所有 id 以“next_”开头的选择的最后一个选项子项,并将其删除。
推荐阅读
- javascript - 使用 fs.rmdir 递归删除后,空文件夹仍然存在
- c++ - 不知道为什么我不能从字符串转换为整数?
- javascript - 一个 btn 的 onClick 我想用 useRef 和 copyToClipboard 获取它的兄弟(输入框)值,将该 btn 的 setState 设置为已复制
- javascript - 将文本从在线 url 加载到 div.innerHTML 时,对 id 或类进行 Javascript 样式设置将不起作用
- r - 将字符向量旋转到具有指定列数的 data.frame
- css - 仅使用 CSS 的边秀
- python-3.x - 在浏览器 Web 应用程序中同时对两个视频进行姿势检测不起作用
- python - 如何在创建 ai 平台笔记本时安装 python 库
- kubernetes - 如何从本地机器访问 Kubernetes 生产环境中的内部服务?(需要:性能和安全性)
- swift - 如何在多个视图控制器的过程中初始化一个类