我正在做一個專案,該專案需要使用 api url 將書籍串列列印到頁面上。
代碼可以創造奇跡,但我正在努力將字符限制為 140 以按照要求進行描述。
function renderItemHtml(item) {
return `<div class="book"><img src="${item.volumeInfo.imageLinks.thumbnail}" class="thumbnails"
alt="${item.singleTitle} by ${item.volumeInfo.authors[0]}" />
<div>
<h4>${item.volumeInfo.title}</h4>
<p><strong>${item.volumeInfo.authors}</strong></p>
<h8>${item.volumeInfo.description}</h8> <-------- what i need to limit
</div>
<br>
<h8>Pages: ${item.volumeInfo.pageCount}</h8>
</div>`
}
uj5u.com熱心網友回復:
只需這樣做:
<h8>${item.volumeInfo.description.slice(0,140)}</h8>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/495944.html
標籤:javascript html api
