废话不多说上代码

//单选框获取值
var receiptType=$('input:radio[name="receipt_type"]:checked').val(); $('#cart_quotations').append('<input type="hidden" name="receiptType" value="' + receiptType + '"/>'); alert("1111="+receiptType); var priceConfig=$('input:radio[name="price_config"]:checked').val(); $('#cart_quotations').append('<input type="hidden" name="priceConfig" value="' + priceConfig + '"/>'); alert("2222="+priceConfig); // var receiptType=$('input:checkbox[name="product_attr_config[]"]:checked').val();
//复选框获取值 var text = $("input:checkbox[name='product_attr_config[]']:checked").map(function(index,elem) { return $(elem).val(); }).get().join(','); $('#cart_quotations').append('<input type="hidden" name="text" value="' + text + '"/>'); alert("选中的checkbox的值为:"+text);
//只需获取个数
var cks = document.querySelectorAll("input[type=checkbox]:checked"); alert("你选中了-->" + cks.length + "<--个");
单选:
<input value="0" name="receipt_type" type="radio">
var receiptType=$('input:radio[name="receipt_type"]:checked').val();
复选:
<input name="product_attr_config[]" id="ind0" value="0" type="checkbox">
 var text = $("input:checkbox[name='product_attr_config[]']:checked").map(function(index,elem) {
                return $(elem).val();

 

相关文章:

  • 2021-09-11
  • 2022-01-07
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-10-27
猜你喜欢
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案