如何使用javascript收集这些信息

时间:2022-11-29 21:18:57

i have the following markup

我有以下标记

<form method="post" action="" id=form_1>
    <input type="hidden" name="night[]" value="1311976800"/>
    <input type="hidden" name="night[]" value="1312063200"/>
    <input type="hidden" name="night[]" value="1312149600"/>
    <input type="hidden" name="night[]" value="1312236000"/>
    <input type="hidden" name="night[]" value="1312322400"/>
    <input type="hidden" name="night[]" value="1312408800"/>
    <input type="hidden" name="night[]" value="1312495200"/>
    <input type="hidden" name="night[]" value="1312581600"/>
    <input type="hidden" name="night[]" value="1312668000"/>
    <input type="hidden" name="night[]" value="1312754400"/>
    <input type="hidden" name="room_id" id="1" value="1"/>
    <a href="rates_ajax.php?action=SubmitBook&lang=it&room_id=1&height=500&width=700" class="thickbox">
    <input type="submit" name="submit" value="Book" class="allInputStuff inputSubmitRates"/></a>
</form>

and i need to collect the name="night[]" how can this be done with Js?

我需要收集名字="night[]"怎么用Js来完成呢?

4 个解决方案

#1


0  

A followup on my comment (based on Thorsten's answer)

以下是我的评论(基于Thorsten的回答)

myarray = [];

$("input[name*='night[]']").each(function(){
    myarray.push($(this).val());
    //u can collect other attributes from $(this) inside here (like name?) 
});

#2


2  

when looking for DOM elements by their names you can use

在通过可以使用的名称查找DOM元素时

$('input[name="night[]"]')

Accessing the value is the same as in any other context

访问该值与在任何其他上下文中相同。

$('input[name="night[]"]').val()

or

$('input[name="night[]"]').each(function(){...})

Hope that's what you're lookin for

希望这就是你想要的

#3


2  

As comma-seperated list:

逗号分离列表:

$('input[name="night[]"').map(function() { return $(this).attr('value'); }).get().join(',');

#4


0  

Assuming you can use jQuery, you can use the following line to search for a specific attribute name:

假设您可以使用jQuery,您可以使用以下行来搜索特定的属性名:

$('input[value*="1312668000"]')

...and from there you can use .val()

…然后使用。val()

#1


0  

A followup on my comment (based on Thorsten's answer)

以下是我的评论(基于Thorsten的回答)

myarray = [];

$("input[name*='night[]']").each(function(){
    myarray.push($(this).val());
    //u can collect other attributes from $(this) inside here (like name?) 
});

#2


2  

when looking for DOM elements by their names you can use

在通过可以使用的名称查找DOM元素时

$('input[name="night[]"]')

Accessing the value is the same as in any other context

访问该值与在任何其他上下文中相同。

$('input[name="night[]"]').val()

or

$('input[name="night[]"]').each(function(){...})

Hope that's what you're lookin for

希望这就是你想要的

#3


2  

As comma-seperated list:

逗号分离列表:

$('input[name="night[]"').map(function() { return $(this).attr('value'); }).get().join(',');

#4


0  

Assuming you can use jQuery, you can use the following line to search for a specific attribute name:

假设您可以使用jQuery,您可以使用以下行来搜索特定的属性名:

$('input[value*="1312668000"]')

...and from there you can use .val()

…然后使用。val()