我需要制作一个页面,在那里你可以看到评论的开头,但必须点击'点击更多'查看评论的其余部分
I need to make a page where you can see the beginning of a review, but have to click on 'click more' to see the rest of the review
我正在为一家企业建立一个网站,他们想要一个专门介绍他们产品好评的页面。
然而,他们不希望巨大的段落占据他们的页面。有没有一种方法可以让每个评论都有他们可以点击的东西,比如只点击其中的一行,然后"点击这里",可以单独展开每个评论?
我刚才请了一位绅士帮我,但只进了一次门。我对所有3个都使用了相同的javascript,我认为这是不正确的。
此外,我认为这将根据评论的长度来扩大页面的高度。我之所以提到这个,是因为我在底部有一个页脚。
无论如何,我想是JavaScript吗?
<div class="comment">
This is the first line of the comment
<span id="extended_comment" style="display:none;">and this is the rest of the comment that is hiddden.</span> <a href="#" id="toggle">click here for more</a></div>
<script type="text/javascript">
var toggle = document.getElementById('toggle');
toggle.onclick = function() {
var extended = document.getElementById('extended_commen…
if(this.innerHTML == 'click here for more') {
extended.style.display = 'inline';
this.innerHTML = 'click here for less';
} else {
extended.style.display = 'none';
this.innerHTML = 'click here for more';
}
};
</script>
将代码封装在一个函数中,并将必要的id传递给该函数,以便设置每个元素的onclick属性。
function setExpandOnclick(toggleButton, extendedComment) {
// your code here, using the arguments rather than hard-coded string ids
}
setExpandOnclick("toggle-button1", "expanded-comment1");
setExpandOnclick("toggle-button2", "expanded-comment2");
你走在了正确的轨道上。
相关文章:
- 添加文字和评论功能更新Div
- 包括用于facebook评论框的JavaScript SDK
- facebook”;添加评论“;popup获胜'不要消失
- Javascript/jQuery压缩一个图像正确的评论帖子,并使用Ajax Laravel 5.2保存到控制器中
- 提交评论不适用于新添加的帖子
- YUI Compressor特别评论在JS中添加了分号
- yammer在手机上嵌入评论不显示回复选项
- AJAX PHP评论框userid=0?回复=“&”;
- 连接流星中的两个收藏(帖子评论)
- 评论的含义是什么;Go Horse'在编码方面?这是某种过程吗
- 为什么我的javascript会被评论
- React/Node应用程序中的Facebook评论插件.js仅在刷新时显示
- 正则表达式以匹配评论
- 将评论发布到网址
- 脸书评论插件如何工作
- 使用 Javascript 检测对社交插件的评论
- 在 Google 评论脚本中将像素更改为百分比
- 以编程方式在Reddit上发表评论
- 显示最新评论,然后向上滚动以查看较早的评论
- Javascript向上/向下投票评论脚本(服务器端完成)