如何在 MasterPage/Content 页面场景中使用 jQuery 脚本?
我利用许多 jQuery 功能和 CSS 在 asp.net 中创建了一个很棒的独立 Web 表单。效果很好。当我将其重新创建为 Web 内容表单(作为 MasterPage 的一部分)时,我的 jQuery 和 javascript 被完全忽略。
我在 MasterPage 中引用了相关的 jQuery 和 CSS。我在母版页底部有一个名为“ScriptContent”的内容占位符。在我的内容页面中,我在这里插入各种 jQuery 方法和 JavaScript。
当我查看页面源时,一切都在那里。然而,可以说,这一切都被忽视了。我做错了什么?
I have created a great stand-alone web form in asp.net utilizing many jQuery features and CSS. It works fine. When I re-create it as a web content form as part of a MasterPage, my jQuery and javascript is completely ignored.
I am referencing the pertinent jQuery and CSS in my of the MasterPage. I have a content placeholder at the bottom of the masterpage called "ScriptContent". In my content page, this is where I plug in the various jQuery methods and javascript.
When I view the page source everything is there. However, it's all being ignored so to speak. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题可能在于,当您的页面作为母版页中的内容页面加载时,所有元素的 id 都会更改以反映它们所在的内容页面。因此,您在 jquery 中使用的 id 将不起作用。
我能想到的选项包括:
Probably the issue is that when your page is loaded as a content page within a masterpage, the ids of all of the elements are altered to reflect what content page they are in. Thus the ids you are using in jquery won't work.
Options I can think of include:
我会将工作版本的源输出与非工作版本的输出进行匹配。
显然,ASP.NET 呈现的内容有所不同。得到差异就会告诉你什么。
由于我没有详细信息,我只能猜测......但听起来您可能遗漏了一些
$(document).ready()
类型功能来在某处启动脚本。I would match the source output of the working version against the output of the non-working version.
Obviously, there's something being rendered out from ASP.NET differently. Getting the difference would tell you what.
Since I have no details, I can only guess...but it sounds like you may have left out some
$(document).ready()
type functionality to kick off your script somewhere.