gpt4 book ai didi

javascript - 在 visual studio 2012 中发布加载图像

转载 作者:行者123 更新时间:2023-11-28 02:00:54 25 4
gpt4 key购买 nike

我是 Visual Studio 2012 的新手,我有一个项目,我需要通过 javascript 将一些图像加载到 View 中,基本上我有一个数组,其中填充了一些项目描述和每个图像的路径,但是当页面加载时该页面无法加载图像,因为它从未找到它们

我用来实现此目的的 javascript 代码是:

      var item = {
name: "",
price: 0,
index: 0,
picURL: ""
};

function Item(name, price, index, picURL) {
this.name = name;
this.price = price;
this.index = index;
this.picURL = picURL;
}

function FillArray() {

var items = new Array();

items[0] = new Item("Gnome1", 32, 001, "Content/img/gnome7.PNG");
items[1] = new Item("Gnome2", 15, 002, "Content/img/gnome14.PNG");
items[2] = new Item("Gnome3", 26, 003, "Content/img/gnome10.PNG");

return items;
}


function addToCart() {
var items = FillArray();
var that = this;
var ul = document.getElementById("list");
for (var i = 0; i < items.length; i++) {

var li = document.createElement("li");
li.id = 'li' + items[i].index;
var currentItem = items[i];

for (p in currentItem) {
var div = document.createElement("div");
if (p.valueOf() == "picURL") {
div.innerHTML = "<img class='miniPic' src='" + currentItem[p].valueOf() + "'/>";
}
else if (p.valueOf() == "price") {
div.innerHTML = p.valueOf() + " : £" + currentItem[p].valueOf();
}
else {
div.innerHTML = p.valueOf() + " : " + currentItem[p].valueOf();
}
li.appendChild(div);
}
}

但是当我调用 View 时,这是我得到的答案:

获取/Home/Content/img/gnome7.PNG 404(未找到)

我试过更改文件的位置,路径,但似乎没有任何效果,当我尝试在我的项目中本地调用一个 json 文件时也是同样的情况,它也说我不能'找不到,所以我认为这可能是我的 Visual Studio 的一种配置,但我无法使其工作,有人可以帮助我吗?这很烦人:(

最佳答案

我的猜测是您没有将图像作为解决方案的一部分,因此它们没有与您的解决方案一起部署。

要解决此问题,请转到 Solution Explorer 并导航到 Content -> Img 文件夹。 (确保选择了解决方案资源管理器顶部的显示所有文件按钮)。
在 img 文件夹中,您应该会看到 gnomeXX 图像。如果它们是灰色的,请右键单击它们并选择 Include in Project

再次尝试构建和运行。

关于javascript - 在 visual studio 2012 中发布加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14002724/

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