我正在尝试在控件中使用 jQuery 插件。控件可以位于的页面通过 UpdatePanel 使用部分回发。我在控件的 PreRender 事件中包含 jQuery 和插件,如下所示:
ScriptManager.RegisterClientScriptInclude(
this,
this.GetType(),
"jquery",
"/_infrastructure/javascript/jquery.js"));
ScriptManager.RegisterClientScriptInclude(
this,
this.GetType(),
"jquery.customPlugin",
"/_infrastructure/javascript/jquery.customPlugin.js");
customPlugin jQuery 插件设置了一个名为“executeCustomPlugin”的新函数。稍后在控件的 PreRender 事件中,我在控件上的一个元素上使用插件:
ScriptManager.RegisterStartupScript(
this,
this.GetType(),
"customPlugin init script",
@"$(document).ready(function() {
$('#elementId').executeCustomPlugin();
});",
true);
但是,当它执行时,我收到 JavaScript 错误:
$('#elementId').executeCustomPlugin is not a function
看起来好像 jQuery 插件根本没有执行,但我在 jQuery.customPlugin.js 文件中设置了 window.alerts,它确实正在执行。
有没有办法解决这个问题?