You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用jQuery将相邻加购按钮移入包裹quantity的engrave_button容器内

实现代码

你可以直接在原有wrap逻辑的基础上调整,一步完成包裹+移动按钮的需求:

// 先完成quantity元素的包裹,同时存储新生成的容器实例
const $engraveContainer = jQuery(".quantity").wrap("<div class=\"engrave_button\"></div>").parent();
// 选中容器后面紧挨着的加购按钮,移入容器内部末尾
$engraveContainer.next("button.single_add_to_cart_button").appendTo($engraveContainer);

如果已经提前执行过wrap操作,只需要单独执行按钮移动逻辑即可,以下写法支持页面存在多个同类结构的场景:

jQuery(".engrave_button").each(function() {
  jQuery(this).next("button.single_add_to_cart_button").appendTo(this);
});

内容的提问来源于stack exchange,提问作者user5853892

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 16:09:00