Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过单击事件绑定使用attr()更改可见性_Javascript_Jquery_Html - Fatal编程技术网

Javascript 通过单击事件绑定使用attr()更改可见性

Javascript 通过单击事件绑定使用attr()更改可见性,javascript,jquery,html,Javascript,Jquery,Html,我试图使用attr()方法更改输入的可见性并选择同级 “添加”按钮适用于所有隐藏元素,但当我想将隐藏属性添加回表单元素时,什么都不会发生 $(函数(){ $(“按钮[name='add'])。单击(addSeries); }); $(函数(){ $(“按钮[name='remove'])。单击(removeSeries); }); 函数addSeries(){ $(this).sides(“输入”).removeAttr(“隐藏”); $(this).sides(“选择”).removeAtt

我试图使用attr()方法更改输入的可见性并选择同级

“添加”按钮适用于所有隐藏元素,但当我想将隐藏属性添加回表单元素时,什么都不会发生

$(函数(){
$(“按钮[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(“+”);
}

图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+
图表类型
纵队
线
叠层柱
堆积线
+