如何让更新面板中的控件与 JQuery 正确配合使用?
我有一个通过更新面板加载的控件,其中的某些项目在用户首次加载页面时最初并未显示。我在这个控件中使用了一些 jquery,我遇到的问题是一个典型的问题,我无法触发 jquery 就绪事件以重新绑定控件中的元素。当控件加载到其自己的页面上时它工作正常,但当它是较大结构的一部分并埋在其中时,这似乎不起作用。
我尝试过绑定到 pageLoad 等方法,但它似乎不起作用,并怀疑它与控件本身内部的 javascript 代码有关。
function pageLoad(sender, args) {LoadScripts();}
所以我有一个这样的结构,
Master page
Aspx Page
Update panel
Other controls
Control with JQuery
我将不胜感激您能提供的任何帮助。
I have a control that is loaded via an update panel and there are items in it that are not initially displayed when the user first loads the page. I’m using some jquery with this control and the problem that I’m having is a typical one where I’m not able to fire the jquery ready event in order to rebind the elements in the control. It works fine when the control is loaded on its own page but when it’s a part of the larger structure and buried inside it this just doesn’t seem to work.
I’ve tried methods like binding to pageLoad but it doesn’t seem to work and suspect that it’s related to the javascript code being inside the control itself.
function pageLoad(sender, args) {LoadScripts();}
So i have a structure like this
Master page
Aspx Page
Update panel
Other controls
Control with JQuery
I would appreciate any help that you can offer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下 jQuery
.live()
,就针对这种情况: http:// /api.jquery.com/live/例如:
如果这对您不起作用,还有一个简单的解决方案:使用 ajax 内容加载脚本。您不必调用
load
或ready
- 只需在新的标记中调用 JavaScript,它就会运行良好- jQuery 已经加载。如果您想使用之前使用的完全相同的代码,请创建一个函数并调用它。
Take a look at jQuery
.live()
, just for such occasions: http://api.jquery.com/live/For example:
If that doesn't work for you, there's still a simple solution: Load the script with the ajax content. You don't have to call
load
orready
- just call your JavaScript in a new<script>
tag, and it will run well - jQuery is already loaded. If you want to use the exact same code you used before, create a function of it and call that.