2015-06-02 5 views
0

Вот форма:Найти следующий родственный одного и того же типа элемента

<form> 
    <input type="text" name="name" id="name"> 
    <label>Phone number *</label> 
    <input type="number" name="phone" id="phone"> 
    <label>Email address *</label> 
    <input type="email" name="email" id="email"> 
    <h3>Event</h3> 
    <label>Event type *</label> 
    <input type="text" name="type" id="type"> 
    <input type="text" name="address" id="address"> 
    <input type="date" name="date" id="date"> 
</form> 

Я переменная инициализируется первый input элемент:

var cur_input; 

Я хочу, чтобы перебрать элементы формы, назначение следующий элемент ввода в переменную cur_input на каждой итерации.

Я пробовал:.

cur_input = cur_input.next(); //failed because there are other elements in between 
cur_input = cur_input.next('input'); //failed for some reason. 
+0

'cur_input.nextAll ('вход') первый()' https://api.jquery.com/nextAll/ – Satpal

+0

/\ это ответ. – lucasnadalutti

+1

@ Satpal это работает! Благодарю. – Ahtsham

ответ

0

Вы можете попробовать это

var inputs = $('form input'); // Get all input under form 
var index = input.index(cur_input); // Get current index 
var next_input = inputs.eq(index+1); // Get next input 
Смежные вопросы