Javascript 通过单击事件绑定使用attr()更改可见性
我试图使用attr()方法更改输入的可见性并选择同级 “添加”按钮适用于所有隐藏元素,但当我想将隐藏属性添加回表单元素时,什么都不会发生Javascript 通过单击事件绑定使用attr()更改可见性,javascript,jquery,html,Javascript,Jquery,Html,我试图使用attr()方法更改输入的可见性并选择同级 “添加”按钮适用于所有隐藏元素,但当我想将隐藏属性添加回表单元素时,什么都不会发生 $(函数(){ $(“按钮[name='add'])。单击(addSeries); }); $(函数(){ $(“按钮[name='remove'])。单击(removeSeries); }); 函数addSeries(){ $(this).sides(“输入”).removeAttr(“隐藏”); $(this).sides(“选择”).removeAtt
$(函数(){
$(“按钮[name='add'])。单击(addSeries);
});
$(函数(){
$(“按钮[name='remove'])。单击(removeSeries);
});
函数addSeries(){
$(this).sides(“输入”).removeAttr(“隐藏”);
$(this).sides(“选择”).removeAttr(“隐藏”);
$(this.parent().append(“-”);
$(this.remove();
}
函数removeSeries(){
console.log($(this));//未记录任何内容
console.log($(this.sides(“输入”));//未记录任何内容
console.log($(this.sides(“select”);//未记录任何内容
$(this).sides(“输入”).attr(“隐藏”);
$(this).sibbins(“select”).attr(“hidden”);
$(this.parent().append(“+”);
$(this.remove();
}
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
您试图将事件附加到将来的元素,您可以使用$(文档)来实现这一点试试这个,希望对你有帮助
$(函数(){
$(文档)。在(“单击”、“按钮[name='add']”,addSeries);
});
$(函数(){
$(文档)。在(“单击”,“按钮[name='remove']”上,removeSeries);
});
函数addSeries(){
$(this).parent().find(“输入,选择”).removeAttr(“隐藏”);
$(this.attr(“name”,“remove”).html(“-”);
}
函数removeSeries(){
$(this).parent().find(“input,select”).attr(“hidden”,“hidden”);
$(this.attr(“name”,“add”).html(“+”);
}
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
您试图将事件附加到将来的元素,您可以使用$(文档)来实现这一点试试这个,希望对你有帮助
$(函数(){
$(文档)。在(“单击”、“按钮[name='add']”,addSeries);
});
$(函数(){
$(文档)。在(“单击”,“按钮[name='remove']”上,removeSeries);
});
函数addSeries(){
$(this).parent().find(“输入,选择”).removeAttr(“隐藏”);
$(this.attr(“name”,“remove”).html(“-”);
}
函数removeSeries(){
$(this).parent().find(“input,select”).attr(“hidden”,“hidden”);
$(this.attr(“name”,“add”).html(“+”);
}
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+