【问题标题】:jQuery checkbox get value and attribute and push to data ajaxjQuery复选框获取值和属性并推送到数据ajax
【发布时间】:2020-11-18 05:48:32
【问题描述】:

我有多个,我想获取值,每个选中复选框的属性。

<input type="checkbox" name="access[]" id="configuration" value="configuration" data-text="Configuration"> Configuration
<input type="checkbox" name="access[]" id="department" value="department" data-text="Departments"> Departments 

我想获取所有选中的复选框并将其存储到数组中并推送到 ajax

var classids = checkboxes.map(function(){ return $(this).attr("id"); }).get();
var val      = checkboxes.map(function(){ return $(this).val(); }).get();
var datatext = checkboxes.map(function(){ return $(this).attr("data-text"); }).get();

如何将这三者合二为一?提前致谢

【问题讨论】:

    标签: jquery ajax checkbox


    【解决方案1】:

    要获取对象数组,您只需映射您正在寻找的相关属性:

    var arr = checkboxes.filter(':checked').map(function(){
      return {classids : this.id, val: this.value, datatext: this.dataset['text']}
    }).get();
    

    【讨论】:

      猜你喜欢
      • 2015-09-21
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 2020-11-08
      • 2010-12-31
      相关资源
      最近更新 更多