gpt4 book ai didi

javascript - 2 张具有相同 src 的图像,一张渲染,一张不渲染。如何?

转载 作者:行者123 更新时间:2023-11-28 22:52:44 25 4
gpt4 key购买 nike

我有 2 个具有相同 src 的 img 标签,“images/export.png”。其中一个显示正确,而另一个显示不正确。有人知道这是怎么发生的吗?

enter image description here

一些上下文:

-使用 Backbone.js,启用 pushState。因此,内部应用程序导航是通过“/location”而不是散列“#location”完成的。

-上下文根是 localhost:8080/NewBizGenerator

-工作图像被硬编码在 index.html 中,而损坏的图像则通过 javascript 插入到 DOM 中。

-“新产品”选项卡当前是默认页面,因此 localhost:8080/NewBizGenerator 将调用 localhost:8080/NewBizGenerator/NewProducts。我发现当我转到 localhost:8080/NewBizGenerator/NewProducts 而不是 localhost:8080/NewBizGenerator 时,损坏的图像会起作用,即使目标页面是同样,localhost:8080/NewBizGenerator/index.html。这让我认为这是一些本地/相对路径问题。

-事实上,当 url 为 localhost:8080/NewBizGenerator 时,每个脚本 src 都认为基本 uri 为 localhost:8080。然而所有的 js 仍然运行,即使当我打开 localhost:8080/js/index.js 它给了我 404。这是真的,因为所有的 js 文件都在 localhost:8080/NewBizGenerator/js.但是为什么js还在执行呢?我已经多次清除浏览器历史记录/缓存文件。当 html 文档位于 localhost:8080/NewBizGenerator/index.html 时,为什么将基本 uri 设置为 localhost:8080。基本 uri 不应该是 localhost:8080/NewBizGenerator 吗?

-如果我右键单击“在新选项卡中查看图像”,工作图像和损坏图像都会显示 404 未找到。这是有道理的,因为图像路径是 "localhost:8080/NewBizGenerator/images/export.png" 并且 img src 尝试访问 "localhost:8080/images/export.png"。 工作图像根本没有任何意义..

我不知道发生了什么,这似乎是本地主机问题加剧了一些缓存/路径问题。

最佳答案

我通过改变解决了这个问题

Backbone.history.start({pushState:true,root:"/NewBizGenerator"});

Backbone.history.start({pushState:true,root:"/NewBizGenerator/"});

我想如果没有结束斜杠,所有资源都试图转到 localhost:8080 而不是 localhost:8080/NewBizGenerator

关于javascript - 2 张具有相同 src 的图像,一张渲染,一张不渲染。如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35400917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com