如何使用Css在Html表Td(列)中加载默认图像 [英] How Can I Load Default Image In Html Table Td(Column) Using Css

查看:92
本文介绍了如何使用Css在Html表Td(列)中加载默认图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我是新来的css,



i有一个douts,


我可以使用css在html table td(column)中加载默认图像吗?



这意味着,



例如,



i在我的桌子上有一张下面的图片td,



< td>< img src =images / im1.jpg/>< / td>



如果假设上面的一个不在根文件夹中,那时它已经在浏览器右侧显示乘法符号。那个时候我想显示根文件夹中的另一个图像。



所以我不想在那个地方显示乘法符号。



如果可能请告诉我一个解决方案

解决方案

你可以写一些Javascript代码来做到这一点。

检查图像存在的功能 -

  function  imageExists(image_url){

var http = new XMLHttpRequest ();

http.open(' HEAD',image_url,);
http.send();

return http.status!= 404 ;

}



参考: http:// stackoverflow.com/a/18837750/1006297 [ ^ ]



为所有图像设置相同的类名,例如 -

 <   img     class   =  img-class    src   =  images / im1.jpg    /  >  



为具有相同类别的所有图像循环并检查它们是否具有有效来源,如果没有分配您想要显示的图像。

类似于 -

 


function (){
jQuery(' 。img-class')。each(< span class =code-keyword> function (){
if (! imageExists(


this )。attr( SRC))

Hi all,

am new in css,

i have one douts,

can i load default image in html table td(column) using css?

that means,

for instance,

i have a below image in my table td,

<td><img src="images/im1.jpg" /></td>

if suppose the above one is not in the root folder that time it has been display multiplication symbol on the browser right. that time i want to show the another image which is in the root folder.

so i dont want to show the multiplication symbol on that place.

if possible please let me know a solution

解决方案

You can write some Javascript code to do that.
Function to check image existence-

function imageExists(image_url){

    var http = new XMLHttpRequest();

    http.open('HEAD', image_url, false);
    http.send();

    return http.status != 404;

}


Reference: http://stackoverflow.com/a/18837750/1006297[^]

Set same class name to all images like-

<img class="img-class" src="images/im1.jpg" />


Loop for all the images those have same class and check if they have valid source and if not assign with the image that you want to show.
Something like-


(function() { jQuery('.img-class').each(function() { if(! imageExists(


(this).attr("src"))


这篇关于如何使用Css在Html表Td(列)中加载默认图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆