使用 asp.net Masterpage 时,浏览器无法识别 JQuery PrettyPhoto()
<script src="Scripts/jquery.prettyPhoto.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<a href="http://www.youtube-nocookie.com/v/Bkjv9SscotY&hl=it_IT&fs=1?rel=0" rel="prettyPhoto" title="">you tube
</a>
<script type="text/javascript">
$(document).ready(
function () {
$(
"a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
<script src="Scripts/jquery.prettyPhoto.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<a href="http://www.youtube-nocookie.com/v/Bkjv9SscotY&hl=it_IT&fs=1?rel=0" rel="prettyPhoto" title="">you tube
</a>
<script type="text/javascript">
$(document).ready(
function () {
$(
"a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
Use
如果您的文件夹结构如下所示
如果您使用 src="scripts/file.js" 引用您的 js 文件,它将在 sam.aspx 和 default.aspx 上工作,但在 bob.aspx 上不起作用
当您不这样做时包含一个前导斜杠,它会在您当前的文件夹中查找。因此,如果您在 bob.aspx 上引用该脚本,它正在寻找此文件 /somefolder/script/file.js
因此,要回答您的问题(假设我做了一个很好的假设),您只需添加一个前导斜杠到 src="script.. 应该是 src="/script/...
If your folder structure looks like this
If you reference your js file using src="scripts/file.js" it will work on sam.aspx and default.aspx, but it won't work on bob.aspx
When you don't include a leading slash, it looks in your current folder. So if you reference that script on bob.aspx, it is looking for this file /somefolder/script/file.js
So, to answer your question (assuming I've made a good assumption), you just need to add a leading slash to src="script.. It should be src="/script/...
ResolveUrl 是一个不错的选择,但它不是理想的解决方案,最好使用正确的 js 路径。由于您将使用友好的 url,然后从根目录获取它并使用 ~ 符号,它基本上告诉服务器从文件夹的根目录启动,因此即使您之前已经发布了应用程序,但少了一个文件夹,比如 inetpub/wwwroot/AppName/ WebUI/
现在将其更改为 inetpub/wwwroot/AppName/ 您的应用程序不会崩溃,任何时候您遇到类似错误时,只需在浏览器上打开页面的源代码,然后单击您的 js 文件链接(如果您能够导航到) js 文件很好,否则可能存在其他情况,例如身份验证已设置但 iis 不允许您访问它。
ResolveUrl is a good option but it is not the ideal solution it would be best if you use the correct path of the js. As you would be using friendly url's then take it from the root and use ~ sign it basically tell's the server to start from root of the folder so even though you have published the app earlier with one less folder lets say inetpub/wwwroot/AppName/WebUI/
and now changed it to inetpub/wwwroot/AppName/ your app wont crash and any time you get a similar error just open the source of the page on the browser and then click on your js file links if you are able to navigate to the js file great else there could be other scenario's like authentication is setup and iis is not allowing you to access it .