[英]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();
}
));
如何將字段類型識別為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
});
你有一些錯誤的語法,在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.