And*_*rus 1 html javascript asp.net-mvc jquery jquery-mobile
如何在输入时阻止表单提交:输入应该像tab一样,它必须:
使用jQuery,jQuery-mobile,ASP.NET MVC4.应用程序使用其基于WebKit的浏览器在Motorola MC2180计算机上运行.这是现代浏览器并支持html5.
数据输入页面:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link href="/Scripts/jquery-mobile/jquery.mobile-1.3.2.css" rel="stylesheet"/>
<script src="/Scripts/jquery/jquery-1.9.1.js"></script>
<script src="/Scripts/jquery-mobile/jquery.mobile-1.3.2.js"></script>
<script src="/Scripts/applibrary.js"></script>
</head>
<body>
<div>
<form id='inputform' method="post"
action ="/Detail/SaveFullDocument">
<input type="hidden" name="_rows" />
<table id="tableId">
<tr>
<th>Code</th>
<th>Quantity</th>
<td>
<input type="button" value="+" onclick="addRow('tableId')" /></td>
</tr>
<tr>
<td>
<input type="text" name="Product" /></td>
<td>
<input type="number" name="Quantity" /></td>
<td>
<input type="button" value="-" onclick="deleteRow(this)" /></td>
</tr>
<tr>
<td>
<input type="text" name="Product" /></td>
<td>
<input type="number" name="Quantity" /></td>
<td>
<input type="button" value="-" onclick="deleteRow(this)" /></td>
</tr>
....
</table>
<input type="button" value="+" onclick="addRow('tableId')" />
<input type="submit" value='Save' />
</form>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
$('#inputform').on('keydown', 'input', function (event) {
if (event.which == 13) {
console.log($(this));
$(this).next('input').focus();
event.preventDefault();
}
});
Run Code Online (Sandbox Code Playgroud)
如果你需要在输入时关注下一个元素,那么就不需要遍历所有输入,因为$(this)它将是目标元素.
| 归档时间: |
|
| 查看次数: |
4773 次 |
| 最近记录: |