Javascript 附录();jquery在单击按钮后添加div
我正在克隆div并将其添加到appendTo的末尾;我希望复制的div在单击按钮后立即追加。到目前为止,它正在末尾添加div 有解决办法吗 我的小提琴: 这就是.appendTo方法所做的。您可以改用.insertAfter方法:Javascript 附录();jquery在单击按钮后添加div,javascript,jquery,clone,Javascript,Jquery,Clone,我正在克隆div并将其添加到appendTo的末尾;我希望复制的div在单击按钮后立即追加。到目前为止,它正在末尾添加div 有解决办法吗 我的小提琴: 这就是.appendTo方法所做的。您可以改用.insertAfter方法: // cache the target element var $parent = $(this).closest(".clonedInput"); // clone the target element // and insert the cloned objec
// cache the target element
var $parent = $(this).closest(".clonedInput");
// clone the target element
// and insert the cloned object after the target element
$parent.clone().insertAfter($parent);
注意,我使用了最近的方法而不是父方法,因为您只想选择第一个/最近的匹配父元素。父母是一种贪婪的方法。这就是appendTo方法的作用。您可以改用.insertAfter方法:
// cache the target element
var $parent = $(this).closest(".clonedInput");
// clone the target element
// and insert the cloned object after the target element
$parent.clone().insertAfter($parent);
注意,我使用了最近的方法而不是父方法,因为您只想选择第一个/最近的匹配父元素。家长是一种贪婪的方法。您可以使用这些方法。after.insertAfter。请检查下面的代码片段
//克隆js
var计数=1;
功能克隆{
如果计数小于5{
var newOne=$this.nestest.clonedInput.clonetrue;
newOne.find'button.clone'.css{'background':+Math.random.toString16.slice-6};
//背景只是为了显示它降落的地方
newOne.insertAfter$this.closest.clonedInput;
计数++;
}
}
$.Counter\u Play.onclick,'button.clone',clone;
.al_icons、.clonedInput、.main_icoset{position:relative;overflow:hidden}.clone{display:block;背景色:红色;padding:10px}.clonedInput{margin top:30px;background:f5}.IconTest{background:green;width:100px;height:30px;text align:center;margin bottom:20px}.main_icoset{width:100%;height:30px}.al_图标{宽度:34px;高度:20px;背景色:263238;颜色:fff;字体大小:7px;行高:22px;文本对齐:居中;浮动:左;页边距右:2px;显示:无;页边距顶部:5px}
在同一div中显示隐藏选定下拉列表中的图标。
仅在按下此按钮后连接
复制
您可以使用方法.after.insertAfter。请检查下面的代码段
//克隆js
var计数=1;
功能克隆{
如果计数小于5{
var newOne=$this.nestest.clonedInput.clonetrue;
newOne.find'button.clone'.css{'background':+Math.random.toString16.slice-6};
//背景只是为了显示它降落的地方
newOne.insertAfter$this.closest.clonedInput;
计数++;
}
}
$.Counter\u Play.onclick,'button.clone',clone;
.al_icons、.clonedInput、.main_icoset{position:relative;overflow:hidden}.clone{display:block;背景色:红色;padding:10px}.clonedInput{margin top:30px;background:f5}.IconTest{background:green;width:100px;height:30px;text align:center;margin bottom:20px}.main_icoset{width:100%;height:30px}.al_图标{宽度:34px;高度:20px;背景色:263238;颜色:fff;字体大小:7px;行高:22px;文本对齐:居中;浮动:左;页边距右:2px;显示:无;页边距顶部:5px}
在同一div中显示隐藏选定下拉列表中的图标。
仅在按下此按钮后连接
复制
简短的回答是use.insertAfter而不是appendTo,尽管您提供的小提琴有几个问题 最值得注意的问题是,您在单击时注册了重复的操作。无论是在html中还是在JS中
<button class="clone btn-floating btn-small waves-effect waves-light red counter_start_btn" onclick="clone();">
请随意研究我对最关键点的修订:
简短的回答是use.insertAfter而不是appendTo,尽管您提供的小提琴有几个问题 最值得注意的问题是,您在单击时注册了重复的操作。无论是在html中还是在JS中
<button class="clone btn-floating btn-small waves-effect waves-light red counter_start_btn" onclick="clone();">
请随意研究我对最关键点的修订:
你的代码正在运行。你需要什么?如果你不编辑和解释你的问题以及你需要了解所有人的内容,那么这个问题值得关闭。你的预期输出是什么?如果你能更清楚一些,有人可以帮助你。现在在按钮点击,它会在div的末尾添加。哪个按钮点击过。我想要哪个按钮clicked 2,3或它应该添加的任何内容。你的代码正在运行。你需要什么?如果你不编辑和解释你的问题以及你需要了解所有人的内容,那么这个问题值得解决。你的预期输出是什么?如果你能更清楚,有人可以帮助你。现在,单击按钮,在div.哪个按钮点击过。我想要哪个按钮点击过2,3或者它应该在它之后添加的任何按钮,而不是在它的末尾。谢谢Joy。它解决了。谢谢Joy。它解决了。