在部分视图中定义 jquery 就绪事件
我已经在 Site.Master 页面中定义了一个 $(document).ready() 事件,我还想在我的部分视图之一中定义另一个 $(document).ready() 事件(用于显示消息和错误消息) ,并且我在所有页面和所有部分视图中调用此部分视图...
部分视图显示在页面中并且还使用模式弹出窗口...所以我尝试这样做,但部分视图中的就绪事件没有触发
我有几件事要问:
- 首先,是否可以做我做的事情我正在尝试做...
- 有些页面具有部分视图,因此页面有两个 $(document).ready() 事件,因此当加载页面时,这两个事件之间是否存在任何冲突...
如果有人可以提供一些例子......
I have defined a $(document).ready() event in Site.Master page and I also want to define another $(document).ready() in one of my partial view (which is use to display msgs and error msgs), and I am calling this partial view in all pages and all partial view ...
the partial views are displayed in the page and also using modal popup ... so I tried to this but the ready event in partial view is not firing
I have few things to ask:
- first, is it possible to do what i am trying to do ...
- there are pages which have partial view and because of it a page has two $(document).ready() events so when the page is loaded, is there be any clashes between these two events ...
and if some body can provide wth some example ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您可以在页面上包含多个就绪事件处理程序。您可以将它们放入站点母版、部分视图和视图页面本身中——您需要的数量都可以。它们必须全部包含在脚本标签中。它们将按照它们包含在最终渲染页面中的顺序触发。请注意,您需要小心确保该部分仅在页面上包含一次,或者多次调用该处理程序也没关系。
示例(不完整):
主:
部分(ErrorDialog)
Yes, you can include multiple ready event handlers on the page. You can put them in the site master, partial views, and view page itself -- as many as you need. They must all be enclosed in script tags. They will fire in the order that they are included in the final, rendered page. Note, you want to be careful to make sure that the partial is included only once on the page or that it doesn't matter if that handler is called multiple times.
Example (not complete):
Master:
Partial (ErrorDialog)
是的,您可以在页面中拥有多个
$(document).ready()
,只需确保在调用此函数之前已包含 jquery 文件即可。在$(document).ready()
内调用的函数
按照请求的顺序调用。jQuery - 多个 $(document).ready ...?
yes you are allowed to have multiple
$(document).ready()
in a page just make sure you have included jquery file before calling this function.Functions
invoked inside$(document).ready()
called in the order they are requested.jQuery - multiple $(document).ready ...?
是的,没错,只要之前的部分视图没有任何错误,您就可以拥有任意数量的 $(document).ready() ,并且它会为所有人触发。
Yep, that's right, as long as previous partial view does not have any error you can have as many $(document).ready() as you want and it will fire for all.