开发者

how can i collect this with javascript

i have the fol开发者_高级运维lowing 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?


when looking for DOM elements by their names you can use

$('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


As comma-seperated list:

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


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

myarray = [];

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


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

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜