admin管理员组文章数量:1429953
I'm using the following jQuery to clone a set of input fields (1 Select field, 2 Text fields and 1 Number field)
$("#add_button").click(function(e) {
e.preventDefault();
$(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text']").val("");
});
Is there any way I can extend this so the cloned number fields don't also contain the values.
I've tried
$("#add_button").click(function(e) {
e.preventDefault();
$(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text|number']").val("");
});
Which doesn't work.
I'm using the following jQuery to clone a set of input fields (1 Select field, 2 Text fields and 1 Number field)
$("#add_button").click(function(e) {
e.preventDefault();
$(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text']").val("");
});
Is there any way I can extend this so the cloned number fields don't also contain the values.
I've tried
$("#add_button").click(function(e) {
e.preventDefault();
$(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text|number']").val("");
});
Which doesn't work.
Share Improve this question asked Jan 4, 2016 at 14:31 LukeLuke 3,5616 gold badges40 silver badges64 bronze badges2 Answers
Reset to default 6The selector in .find("input[type='text|number']")
is incorrect. To select multiple elements, separate the selectors by ma.
.find("input[type='text'], input[type='number']")
See Multiple Selectors
To set empty string as value to all the input
elements, use element selector.
.find('input').val('')
You must use a multiple element selector using ,
to separate each selector; like:
$("#add_button").click(function(e) {
e.preventDefault();
$(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text'], input[type='number']").val("");
});
本文标签: javascriptjQuery find() inputs of multiple typesStack Overflow
版权声明:本文标题:javascript - jQuery .find() inputs of multiple types - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745440302a2658415.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论