JQuery: Turn array input values into a string optimization

前端 未结 3 494
迷失自我
迷失自我 2020-12-18 12:20

using jQuery I have the following code:

var selectedIdsArray = $(\"#selectId option:selected\").map(function(){return this.value;});
var selectedIdsStr = $.m         


        
相关标签:
3条回答
  • 2020-12-18 13:03

    You can also change the second line to this:

    var selectedIdsStr = selectedIdsArray.get().toString()
    
    0 讨论(0)
  • 2020-12-18 13:08

    You could change the second line like this:

    var selectedIdsStr = selectedIdsArray.get().join(',');
    
    0 讨论(0)
  • 2020-12-18 13:14
    var selectedIdsStr = $("#selectId option:selected").map(function(){
       return $(this).val();
    }).get().join(",");
    

    adapted from http://docs.jquery.com/Traversing/map#callback

    0 讨论(0)
提交回复
热议问题