最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

get a single textbox value from array of textbox jqueryjavascript - Stack Overflow

programmeradmin2浏览0评论

I have an array of text inputs like this:

<input type="textbox" name="col[]">
<input type="textbox" name="col[]">
<input type="textbox" name="col[]">

They are generated at run time using an "add" button.

I can fetch textbox array values using

$('input[name="col[]"]').each(function(){
  alert($(this).val());
});

But if I just need 2nd textbox value then will I fetch it directly without looping through array using jquery?

I appreciate someones help.

I have an array of text inputs like this:

<input type="textbox" name="col[]">
<input type="textbox" name="col[]">
<input type="textbox" name="col[]">

They are generated at run time using an "add" button.

I can fetch textbox array values using

$('input[name="col[]"]').each(function(){
  alert($(this).val());
});

But if I just need 2nd textbox value then will I fetch it directly without looping through array using jquery?

I appreciate someones help.

Share Improve this question asked Jan 15, 2013 at 20:22 HiralHiral 1535 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Use .eq() to select it:

var $textboxes = $('input[name="col[]"]')

var value1 = $textboxes.eq(0).val();
var value2 = $textboxes.eq(1).val();
...
发布评论

评论列表(0)

  1. 暂无评论