本文介绍了如何设置默认按钮,按MVC3,剃须刀中的回车键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何按回车键设置默认按钮.无法使用我的jquery脚本代码.
我的代码是这样的.
Hi All,
How to set the default button on press enter key. not working my jquery script code.
my code like this.
@*<script type="text/javascript"> $(document).ready(function () {
$("#MyForm").keypress(function (e) {
kCode = e.keyCode || e.charCode //for cross browser
if (kCode == 13) {
var defaultbtn = $(this).attr("DefaultButton");
$("#" + defaultbtn).click();
return false;
}
});
});
</script>*@
<script type="text/javascript">
var ButtonKeys = { "EnterKey": 13 };
$(function () {
$("#MyForm").keypress(function (e) {
if (e.which == ButtonKeys.EnterKey) {
var defaultButtonId = $(this).attr("DefaultButton");
$("#" + defaultButtonId).click();
return false;
}
});
});
</script>
@using (Html.BeginForm("NewCustomer", "Customer", FormMethod.Post, new { DefaultButton = "btnContinue", id = "MyForm", Name = "MyForm" }))
{ <div id="login">
<table style="vertical-align:5px;">
<tr>
<td>
Enter Your Email ID
@Html.TextBoxFor(m => m.EmailId, new { @tabindex = "1", @Id = "subemail", @Name = "subemail"})
</td>
</tr>
<tr>
<td>
Select Your City</h2>
@Html.DropDownListFor(m => m.Address.City, new SelectList(ViewBag.CityList, "ItemValue", "ItemText"), new { @tabindex = "2"})
</td>
</tr>
<tr>
<td>
<input type="submit" value="Great Deals" class="btn" name="Continue" id="btnContinue" runat="server" tabindex="3"/>
</table>
</div>
但是在选择城市后再按Enter键,但没有用.
请帮我谢谢你.
But am select the city after then press the enter key but not working.
Please help me thanking you.
推荐答案
这篇关于如何设置默认按钮,按MVC3,剃须刀中的回车键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!