Get all text field value located in a specific class

后端 未结 5 1390
余生分开走
余生分开走 2020-12-24 11:51

I want to get all fields that are located in a single class name, for example my code like.

相关标签:
5条回答
  • 2020-12-24 12:13

    If you want all the values into an array, you can do this:

    var texts= $(".test .text-field").map(function() {
       return $(this).val();
    }).get();
    
    0 讨论(0)
  • 2020-12-24 12:24

    From cwallenpoole's answer following should work

    $.each( $(".test input[type=\"text\"]"), function(index, ele){
       alert( ele.val());
     });
    
    0 讨论(0)
  • 2020-12-24 12:27

    Have you tried this:

    $(".test input[type=\"text\"]")
    
    0 讨论(0)
  • 2020-12-24 12:28

    Try this:

    $(".test .text-field")
    

    EDIT:

    To get values try this:

    $(".test .text-field").each(function() {
        alert($(this).val());
    });
    
    0 讨论(0)
  • 2020-12-24 12:33

    Here's another method to obtain an array of the input values:

    Array.from($('.test .text-field').get(), e => e.value)
    

    Or alternatively:

    [].map.call($('.test .text-field').get(), e => e.value)
    
    0 讨论(0)
提交回复
热议问题