当调用getJSON时,防止滚动到顶部
Prevent scroll to the top when getJSON is called
我现在很困惑。
下面是我的代码: $("#combinations").on("change", "input", function (e) {
e.preventDefault();
console.log(e)
var $button, $row, $group, $form, $barcodeValidation, url, barcodeVal;
$button = $(this);
$row = $button.closest(".input-group");
$group = $row.closest(".form-group");
$form = $group.closest("form");
$barcodeValidation = $row.find("#barcode-validation");
barcodeVal = $row.find("input").val();
url = "/Product/CheckBarcode";
var productNumber = $form.find("#Product_Number").val();
$.getJSON(url, {
barcode: barcodeVal,
productNumber: productNumber
}).done(function (result) {
e.preventDefault();
}).fail(function (result) {
});
});
所以当一些组合输入改变时,我想向服务器发出请求并检查一些。但由于某种原因,每次这个请求发生时,页面一直滚动到顶部。如果我注释Ajax请求部分,一切都很好。
我如何防止这种行为?
编辑
标记:
<div class="row">
<div class="col-md-12">
<div class="combinations">
@Html.EditorFor(m => m.Combinations)
</div>
</div>
</div>
编辑器包含一些输入字段。
The . preventdefault ();
相关文章:
- 滚动固定滚动顶部()的跳跃效果
- 当偏移量改变时滚动顶部
- 滚动顶部在滑动后不起作用切换
- 使滚动顶部始终检查
- 页面滚动在粘性页脚布局中保持滚动顶部位置
- 滚动顶部闪烁-Internet Explorer
- j查询滚动顶部麻烦
- 我如何使用滚动顶部()获取HTML文档的位置
- 滚动顶部到元素 - 20px
- JQuery 偏移和滚动顶部问题
- 滚动事件仅在滚动顶部时触发
- 单击并滚动顶部
- 每次在顶部滚动顶部重置
- IE <选择>滚动顶部
- 打开对话框正在更改我的滚动顶部位置
- 为什么有时滚动顶部/滚动左不可写
- 滚动顶部 Jquery
- 数据表在页面更改时滚动顶部
- 使用滚动顶部显示滚动的像素
- 可以 jQuery invalidHandler 通过父窗口中的 iframe 滚动顶部