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();
}
));
如何将字段类型识别为select
或radio
或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
});
关于javascript - 如何在jQuery中获取输入类型复选框和单选框的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21061610/