使用应该在第一页加载和随后的 Ajax 回发时注册的 JQuery。 应用此控件的控件位于更新面板内。现在我在做什么
在 document.ready
和 sys.application.add.load
中以两种方式注册相同的函数,因此它适用于更新面板内的控件和控件在更新面板之外。
$(document).ready(function () {
CheckMaxlength();
//If Text area is placed inside update panel then apply restriction for texarea size.
Sys.Application.add_load(function () {
CheckMaxlength();
});
});
我想知道使用更新面板内部和外部更新面板的控件的确切方式是什么
最佳答案
我不确定你想做什么,但我怀疑delegated events可能是你的答案。
Delegated events have the advantage that they can process events from descendant elements that are added to the document at a later time. By picking an element that is guaranteed to be present at the time the delegated event handler is attached, you can use delegated events to avoid the need to frequently attach and remove event handlers.
例如,您可以向所有文本区域添加功能,而不管它们是何时添加到页面中的
$( "body" ).on( "click", "textarea", function() {
alert( $( this ).val() );
});
您的情况的第一个好处是任何时候添加到更新面板的任何文本区域都将获得委派的功能。
此外,如果您想针对更新面板内和更新面板外的文本设置不同的行为,您也可以这样做。
$("body").on('click', 'textarea', function () {
alert( "outside" + $(this).val());
});
$(".update-panel").on('click', 'textarea', function () {
alert("inside: " + $(this).val());
//stop the event from propagating up to the body
event.stopPropagation();
});
另请注意,运行此代码时,只有 body
和 upload-container
需要准备就绪。它不需要文本区域在那里,因此您不必在 Sys.Application.add_load
中运行它。
关于javascript - 在页面加载和随后的 ajax 回发时注册 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32781260/