Javascript 在部分视图中保留滚动事件
有没有办法在局部视图中持久化滚动事件?我有一个表,它使用了一个滚动事件,该事件是在索引页面中启动部分的ajax表单post之后所需的。有没有一种方法可以做到这一点,而不用将js放在局部视图中Javascript 在部分视图中保留滚动事件,javascript,ajax,asp.net-mvc,partial-views,Javascript,Ajax,Asp.net Mvc,Partial Views,有没有办法在局部视图中持久化滚动事件?我有一个表,它使用了一个滚动事件,该事件是在索引页面中启动部分的ajax表单post之后所需的。有没有一种方法可以做到这一点,而不用将js放在局部视图中 scroll事件在表中。我找到了解决这些问题的方法,因为scroll事件不冒泡,我将scroll事件及其所需元素放在一个冒泡的事件中,从而在呈现Ajax局部视图后持久化scroll事件 例如: $("#parent").on("click", "#child", function (even
scroll事件在表中。我找到了解决这些问题的方法,因为scroll事件不冒泡,我将scroll事件及其所需元素放在一个冒泡的事件中,从而在呈现Ajax局部视图后持久化scroll事件 例如:
$("#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);
});
}
$(“#父项”)。在(“单击”,“子项”,函数(事件){
$.ajax({
url:urlForPost,
类型:“POST”,
数据:$(“表单”).serialize(),
contentType:“application/x-www-form-urlencoded;charset=ISO-8859-15”
}).done(函数(所有数据){
//首先删除IE9的空白
var expr=new RegExp('>[\t\r\n\v\f]*我找到了一个解决此类问题的方法,因为滚动事件不会冒泡,我将滚动事件及其所需元素放入一个冒泡的事件中,从而在呈现Ajax局部视图后持久化滚动事件
例如:
$("#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);
});
}
$(“#父项”)。在(“单击”,“子项”,函数(事件){
$.ajax({
url:urlForPost,
类型:“POST”,
数据:$(“表单”).serialize(),
contentType:“application/x-www-form-urlencoded;charset=ISO-8859-15”
}).done(函数(所有数据){
//首先删除IE9的空白
var expr=new RegExp('>[\t\r\n\v\f]*