2015-06-02 83 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 
相关问题