jQuery .each() with input elements

前端 未结 4 1421
攒了一身酷
攒了一身酷 2020-12-15 16:16
//save tablet
jQuery(\"#savetablet\"+jTablets[i].idtablets).on(\'click\', function()
{
    alert(\"alertsepy2...\");
    console.log(jTablets[i].idtablets);
    jQue         


        
相关标签:
4条回答
  • 2020-12-15 16:55

    To extract number :

    var arrNumber = new Array();
    $('input[type=number]').each(function(){
        arrNumber.push($(this).val());
    })
    

    To extract text:

    var arrText= new Array();
    $('input[type=text]').each(function(){
        arrText.push($(this).val());
    })
    

    Edit : .map implementation

    var arrText= $('input[type=text]').map(function(){
        return this.value;
    }).get();
    
    0 讨论(0)
  • 2020-12-15 17:03
    $.each($('input[type=number]'),function(){
      alert($(this).val());
    });
    

    This will alert the value of input type number fields

    Demo is present at http://jsfiddle.net/2dJAN/33/

    0 讨论(0)
  • 2020-12-15 17:04

    Assume if all the input elements are inside a form u can refer the below code.

     // get all the inputs into an array.
    
        var $inputs = $('#myForm :input');
    
        // not sure if you wanted this, but I thought I'd add it.
        // get an associative array of just the values.
        var values = {};
        $inputs.each(function() {
            values[this.name] = $(this).val();
        });
    
    0 讨论(0)
  • 2020-12-15 17:07

    You can use:

    $(formId).serializeArray();
    
    0 讨论(0)
提交回复
热议问题