[英]how to get types of input-type checkbox and radio in jQuery
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
?如何将字段类型识别为select
或radio
或checkbox
?
You had some wrong syntax, missing a function declaration inside the each()
, but actually you can write it more simple, like:你有一些错误的语法,在each()
中缺少一个函数声明,但实际上你可以把它写得更简单,比如:
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();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.