2013-08-02 32 views
0

所以情况就是这样。每个获得特定值<input>

我有2 <input>里面<td>它有无限数量。例如:

<td> 
    <input type="text" name="cust_name" onchange="check(this)" /> 
    <input type="hidden" name="cust_id" value="10" /> 
</td> 
<td> 
    <input type="text" name="cust_name" onchange="check(this)" /> 
    <input type="hidden" name="cust_id" value="12" /> 
</td> 
...... 

thischeck(this)含有cust_name值。但是,我怎样才能得到具有相同功能的特定cust_id值? (check()

划定:

function check(part_element){ 
    console.log($(part_element).val()); 
    console.log(getting particular cust_id value); //here is the part 
} 

回答

1

您可以使用next

function check(part_element){ 
    console.log($(part_element).val()); 
    console.log($(part_element).next().val()); 
} 
1

可以使用.next()找到下一个兄弟,在这种情况下,它是cust_id元素

function check(part_element){ 
    console.log($(part_element).val()); 
    console.log($(part_element).next().val()); //here is the part 
} 
0

这已经有了一个被接受的答案,但在这种情况下,我认为使用jQuery并没有使这个更容易,甚至更复杂:

function check(el) { 
    console.log(el.value); 
    console.log(el.nextSibling.value); 
}