jQuery('.pricefield select','.pricefield input').each
(jQuery(this).change (function (){
alert(jQuery(this).attr("type")); //it give undefined
alert(jQuery(this).is(':input')); //it gives false
var allInputs = jQuery(":input");
alert(allInputs.attr('type')); //it gives hidden
get_sum();
}
));
How can I can identify the field type as select
or radio
or checkbox
?
jQuery('select, input', '.pricefield').on('change', function () {
var tag = $(this).prop('tagName'); // return "select", "input" etc
var type = $(this).prop('type'); // return "radio", "checkbox" etc
});
You had some wrong syntax, missing a function declaration inside the each()
, but actually you can write it more simple, like:
jQuery('.pricefield select, .pricefield input').change(function () {
alert(jQuery(this).attr("type"));
alert(jQuery(this).is(':input'));
var allInputs = jQuery(":input");
alert(allInputs.attr('type'));
get_sum();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.