我有一个关于 jQuery 函数的问题。我有一个功能,一旦浏览器准备就绪,该功能就会找到一个特定的表,然后向其添加悬停和单击功能。
我试图从 asp .net 页面中的代码后面调用此函数,因为一旦有人添加到数据库,更新面板就会触发并检索 gridview(受文档中函数影响的表) 。准备好)。当它回来时,它又是普通的 table 。
这里是原始函数:
$("#GridView1").find("tr").click(function(e) {
var row = jQuery(this)
//var bID = row.children("td:eq(0)").text();
$('#tbHiddenBatchID').val(row.children("td:eq(0)").text());
//Took out repetitive code, places values from table into modal
e.preventDefault();
$('#modalContentTest').modal({ position: ["25%", "5%"] });
//row.addClass('highlight');
//$('#tbEdit').val(bID);
});
//here is the function that adds hover styling
$("#GridView1").find("tr").click(function() {
return $('td', this).length && !$('table', this).length
}).css({ background: "ffffff" }).hover(
function() { $(this).css({ background: "#C1DAD7" }); },
function() {
$(this).css({ background: "#ffffff" });
});
好的,我尝试做的是创建一个函数,在 document.ready 上调用它,并在数据库更新后的代码中调用它。
这是我做的:
function helpGrid() {
$("#GridView1").find("tr").click(function(e) {
var row = jQuery(this)
//var bID = row.children("td:eq(0)").text();
$('#tbHiddenBatchID').val(row.children("td:eq(0)").text());
//
e.preventDefault();
$('#modalContentTest').modal({ position: ["25%", "5%"] });
//row.addClass('highlight');
//$('#tbEdit').val(bID);
});
//Haven't even tried to add the hover stlying part yet; can't get this to work.
}
当我尝试调用 helpGrid();我收到一个未定义的错误...
显然我是一个 jQuery 新手,但我确实有 jQuery 在行动,我现在正在搜索它寻找答案......
请帮忙..
谢谢!!!
最佳答案
由于您使用的是更新面板,因此整个页面不会回发,并且 document.ready 的东西永远不会被击中...下面是您可以添加一个函数以在更新结束时运行的地方,因此 resetMyTableStuff() ;是您施展魔法的地方...
尝试添加这样的东西......
function pageLoad() {
if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequest);
}
}
function endRequestHandler(sender, args) {
resetMyTableStuff();
}
function initializeRequest(sender, args) {
//just in case you need to do it...
}
关于asp.net - jQuery 函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/639883/