有没有办法在部分 View 中保留滚动事件?我有一个表,它使用在索引页面中启动的部分的 ajax 表单发布后需要的滚动事件。有没有办法在不将 js 放入局部 View 本身的情况下执行此操作。
滚动事件在桌面上。
最佳答案
我找到了解决此类问题的方法,因为滚动事件不会冒泡,我将滚动事件及其所需的元素放在一个冒泡的事件中,从而在渲染 Ajax 部分 View 后保留滚动事件。
示例:
$("#parent").on("click", "#child", function (event) {
$.ajax({
url: urlForPost,
type: "POST",
data: $("form").serialize(),
contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15"
}).done(function (allData) {
//First Remove white space for IE9
var expr = new RegExp('>[ \t\r\n\v\f]*<', 'g');
allData = allData.replace(expr, '><');
$("#parent").html(allData);
ResizeContent();
$("#id1").scroll(function () {
$("#id2").scrollLeft($("#id1").scrollLeft());
});
}).fail(function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
}
关于javascript - 在部分 View 中保留滚动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15298712/