2012-03-31 155 views
1

我在页面上有多个按钮,我想模拟点击NEXT按钮。jQuery点击下一步按钮

$('input, select').keydown(function(e){ 
    if(e.which == 13) 
    //$('input[type*=button]').click(); 
    $(this).next('input[type*=button]').click(); 
}); 

HTML:

<tr> 
    <td class="cell"> 
     <input type="text" name="domain" class="entryfield" value="http://"> 
    </td> 
</tr> 
<tr> 
    <td class="cell" align="right" colspan="2"> 
     <input type="button" class="button" value="Get IP" id="submitDomain"/> 
    </td> 
</tr> 

注释的代码工作,但点击页面上的所有按键。

任何帮助表示赞赏,谢谢。

+6

这取决于你的HTML是什么样子... – 2012-03-31 15:34:06

+0

嘿@AndrewWhitaker,你能解释一下吗?我必须使用.parents()吗? – Prash 2012-03-31 15:38:05

+0

您可能正在寻找以下按钮。但是'next('somehere')'只是一个条件语句。它不会自动给你下面的按钮。只是,如果下一个*是一个按钮,它将在下一步执行。 – Marnix 2012-03-31 15:39:57

回答

2

鉴于您的标记:

$("input, select").keydown(function() { 
    $(this).closest("tr").next().find("input:button").click(); 
}); 

基本上,找到closest表行,然后找到紧接其后tr。里面有trfind你想点击的按钮。

下一页找到紧随同胞,在该事件发生在实际上不会找到任何东西input所以调用next

例子:http://jsfiddle.net/N3WBP/

+0

感谢这一点,不知道next()函数的工作原理。这个HTML是一个婊子工作。再一次,谢谢! – Prash 2012-03-31 15:50:28

+0

没问题,很高兴帮助! – 2012-03-31 15:50:45