【发布时间】:2017-12-04 20:08:56
【问题描述】:
专业人士您好
我的 asp.net 页面中有一个表格
<div role="tabpanel" class="tab-pane fade in active" id="a" aria-labelledby="all-tab">
<div class="agile-news-table">
<div class="w3ls-news-result">
<h4>Search Results : <span>25</span></h4>
</div>
<table id="table-breakpoint">
<thead>
<tr>
<th>No.</th>
<th>Album Name</th>
<th>Year</th>
<th>Artist</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td class="w3-list-img">
<a href="single.html"><img src="images/m1.jpg" alt="" /> <span>Al Muallim</span></a>
</td>
<td>2003</td>
<td class="w3-list-info"><a href="comedy.html">Sami Yusuf</a></td>
</tr>
<tr>
<td>2</td>
<td class="w3-list-img">
<a href="single.html"><img src="images/m2.jpg" alt="" /> <span>Barakah</span></a>
</td>
<td>2017</td>
<td class="w3-list-info"><a href="genre.html">Sami Yusuf</a></td>
</tr>
</tbody>
</table>
</div>
</div>
您看到的表格是一个 html 模板,它有 25 行,正如您在 <h4> 中的 <span> 中看到的那样。
我通过 ajax 获取专辑的数据,我希望通过 jQuery 分配表中的值。
我在 25 行上使用了一个循环,对于每一行,我必须在第二个 <td> 中到达 <img> 以更改其 src ,与它旁边的 <spane> 相同以更改其中的文本专辑名称。
在第三个<td> 里也改一下年份吧。
在第四个<td> 我需要更改<a> 的href 和<a> 的文本,这是艺术家的名字。
你看到id="a"在第一个<div>中了吗,这是因为我喜欢这个表中的每个字母表,其中字母是那个表的id,
并且有一个A- ZList of the letters where a click a letter will make request to bring the albums with names with the first at the clicked letter, and assing them from the XmlHttpRequest.responseText to the table.
这就是为什么我在这个 jQuery 代码中使用 letter 变量来传递第一个 <div> 的 id 以将值分配到表中,因为还有另一个 <div id="b"> 等等
function AssignAlbumIntoDOM(albumName, albumYear, albumPhotoPath, artistName, albumsCount, i, letter) {
if (i < 25 && i >= 0) { // keep calling until i is 25
jQuery("#" + letter + " h4 span").text(albumsCount);
jQuery("#" + letter + " table tbody").children().eq(i).children().eq(1).children().eq(0).children().eq(0).attr("src", albumPhotoPath);
jQuery("#" + letter + " table tbody").children().eq(i).children().eq(2).text(albumYear);
jQuery("#" + letter + " table tbody").children().eq(i).children().eq(3).children().eq(0).text(artistName);
}
}
<td> 和第四个 <td> 中分配 albumYear 和 artistName,但在第二个
<td> 中无法更改 albumPhotoPath <img> @ 987654349@ 和 albumName 中的 <span> 我可以扩展问题
从解释中可以看出,这个页面是一个搜索页面
而且我有专辑的所有信息,除了专辑的歌曲,那么如何在点击第二个@987654354 中的
<img> 后将这些信息传递到一个名为Single.aspx 的页面,以显示专辑信息及其歌曲@,而在Single.aspx 我只需要通过ajax 来请求专辑的歌曲而不是所有的信息。 我认为传递将在第二个
<td> 中的<a> 的href 中作为QueryString,还有其他方法吗? 非常感谢你
【问题讨论】:
-
答案未删除...我记得这个有一个很酷的演示,愉快的编码。
标签: javascript jquery html