我是JavaScript的新手,并试图想出如何将Alt属性添加到数组中。这是我到目前为止所拥有的。我该如何在哪里添加?我正在考虑在body / table中添加alt ='“但显然这不起作用。
<script type="text/javascript">
var pictures = new Array();
pictures[0] = new Image();
pictures[0].src = "image.jpg";
pictures[1] = new Image();
pictures[1].src = "image2.jpg";
<body>
var x = "<table>";
for (var y=0; y<rows; y++) {
x += "<tr> ";
for (var j=0; j<columns; j++) {
var ix = (y * rows + j) % pictures.length;
var id = y + "-" + j;
x += "<td> <img src=' " + pictures[ix].src +
"' " +
" id='" + id + "' " +
" height='300' width='300' ></td>";
答案 0 :(得分:0)
&#34; Alt和#34;如果图像无法正确显示,则属性中的文本将显示。
x += "<td> <img src=' " + pictures[ix].src +
"' " +
" id='" + id + "' " +
" height='300' width='300' alt='image_" + j + "' ></td>";