用JavaScript将我的描述中的字符限制为140个字符
我正在研究一个项目,该项目需要使用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>`
}
I'm working on a project that requires a list of books to be printed onto the page using an api url.
Code works wonders, but I'm struggling to limit the characters to 140 for the description as requested.
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>`
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是这样做:
Just do this: