I have a folder with images called " LaptopsImages ".
In my file called laptops.php i have an array list with different laptops with variables like: title, brand, price, description, spec and pictures names. My array list is convert to XML DOM tree.
On my file called product.html i wrote a code that take every product data into the variables and display it:
var title = $theProduct.find('title').text();
var brand = $theProduct.find('brand').text();
var price = $theProduct.find('price').text();
var description = $theProduct.find('description').text();
var spec = $theProduct.find('spec');
var imageFilename = $theProduct.find('picture').text();
document.getElementById("title").innerHTML=title
document.getElementById("brand").innerHTML=brand
document.getElementById("price").innerHTML=price
document.getElementById("description").innerHTML=description
document.getElementById("spec").innerHTML=description
I have accomplished to display every product data into my html except the pictures for each laptop. Is any way that i can display pictures with the name they have already from my variable? Assume that the pictures have names " 0001.jpg , 0002.jpg " and so on.
Every picture can be taken from: var imageFilename=$theProduct.find('picture').text();
document.getElementById("picture").src = imageFilename
如果有带有 id picture
的<img>
标签
如果您使用 jquery,您可以执行以下操作:
$("#picture").attr("src", imageFilename);
document.getElementById('myImage').src = imageFileName;
If you need the name from the ImageFileName then you can use:
name= imageFileName.substring(0, imageFileName.length - 4);/*to chop off .JPG*/
With Jquery:
$("#myImage").attr("src", imageFilename);
document.getElementById("price").innerHTML= "<img src=\"" + imageurl+ "\">";
您可以使用此代码在内部 div 中显示完整图像,其中 div id 是价格
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.