Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用多个输入字段填充数组_Javascript_Jquery_Arrays - Fatal编程技术网

Javascript 用多个输入字段填充数组

Javascript 用多个输入字段填充数组,javascript,jquery,arrays,Javascript,Jquery,Arrays,我想使用jQuery用输入字段中的值填充一个数组,其中的类为“seourl” <input id="title" class="seourl" name="title" type="text" value="???"> <input id="subtitle" class="seourl" name="title" type="text" value="???"> <input id="subtitle2" class="seourl" name="title" t

我想使用jQuery用输入字段中的值填充一个数组,其中的类为“seourl”

<input id="title" class="seourl" name="title" type="text" value="???">
<input id="subtitle" class="seourl" name="title" type="text" value="???">
<input id="subtitle2" class="seourl" name="title" type="text" value="???">

<a id="getFriendlyUrl" href="">get url friendly</a>
如果需要,可以使用jQuery获取.value

return $(this).val();
无论哪种方式,最终都会得到一个值数组。

html:

$('.seourl').each(function(ele){
    arr_str.push($(ele).val());
});

jsfiddle:

。今天是什么时候?.map的返回值不是已经是数组了吗?我更喜欢你的答案:@法布里西奥马特:不,那将是本机Array.prototype.map或$.map。此函数返回一个jQuery对象:-哦,是的,我的错,我在想美元地图+1 =]
return $(this).val();
$('.seourl').each(function(ele){
    arr_str.push($(ele).val());
});
$("#getFriendlyUrl").click(function() {
    var arr_str = new Array();

    $('.seourl').each(function() {

        arr_str.push( $(this).val() );
    })'

});
<input id="title" class="seourl" name="title" type="text" value="???">
<input id="subtitle" class="seourl" name="title" type="text" value="???">
<input id="subtitle2" class="seourl" name="title" type="text" value="???">

<a id="getFriendlyUrl" href="">get url friendly</a>​
$("#getFriendlyUrl").click(function() {

    var arr_str = new Array();

    $(".seourl").each(function(index, el) {
     arr_str[index] = $(el).val();   
    });
    alert(arr_str[0] + arr_str[1] + arr_str[2]);

});​
$("#getFriendlyUrl").click(function() {

    var arr_str = new Array();
    $('.seourl').each(function() {
        arr_str.push($(this).attr('value'));

    });
    alert(arr_str);
});