[英]How to use enter to move cursor to next textbox instead of submit?
屏幕快照我試圖通過按Enter
將光標移動到下一個文本框。
這是我的aspx代碼:
<strong>
<asp:Label ID="bondtapelbl" runat="server" Text="Bond Tape :" Font-Bold="True" Font-Italic="False" Font-Names="Arial Black" Font-Size="Medium"></asp:Label>
</strong>
<asp:TextBox ID="bondtape" runat="server" BackColor="#CCCCCC" Height="35px" Font-Size="Medium" Width="130px" CssClass="bt" />
<span class="auto-style6">&</span><strong>
<asp:Label ID="productranklbl" runat="server" Text="Product Rank :" Font-Bold="True" Font-Italic="False" Font-Names="Arial Black" Font-Size="Medium"></asp:Label>
<asp:TextBox ID="productrank" runat="server" BackColor="#CCCCCC" Height="35px" Font-Size="Medium" Width="130px" CssClass="pr" />
<asp:Button ID="bontapeButton" Text="Search" runat="server" BackColor="#3399FF" BorderStyle="None" CssClass="btsearch" ForeColor="White" Height="39px" Width="80px" />
</strong></td>
我為此使用javascript。 問題在於,它不會自動將光標移動到下一個文本框,而是自動執行搜索按鈕。
<script type="text/javascript">
//Bind keyup event to textbox
$('btsearch[type="bondtape"]').keyup(function (event) {
if (e.keyCode == 13) {
$("pr").next().focus();
}
});
</script>
我的JavaScript基於我從其他論壇獲得的答案:
$('input[type="textbox"]').keyup(function(e) {
if(e.keyCode == 13) {
$(this).next().focus();
}});
我只學習了javascript的2/3天,所以我真的不知道我錯了哪一部分。 如果有人可以幫助我,我將不勝感激。 提前致謝。
好吧,我只想分享我得到的答案。 這是我從中得到答案的鏈接(您也可以嘗試演示): http : //www.latentmotion.com/downloads/enter-to-tab.html
下面是與我的項目一起使用的javascript。 我得到的解決方案是我用下面的javascript替換了關於該問題的javascript。 我希望這可以幫助其他人。
$(document).ready(function(){
$("input").not( $(":button") ).keypress(function (evt) {
if (evt.keyCode == 13) {
iname = $(this).val();
if (iname !== 'Submit'){
var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
var index = fields.index( this );
if ( index > -1 && ( index + 1 ) < fields.length ) {
fields.eq( index + 1 ).focus();
}
return false;
}
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.