我正在尝试使用 javascript 子字符串读取更多按钮,但我的代码不起作用,我可以隐藏文本,但无法在单击时显示更多内容
<p class="pr">More than 200</p>
<button class="btn">Read more</button>
<script>
var pr = document.querySelectorAll('.pr');
var btn = document.querySelectorAll('.btn');
for (var i = 0; i < pr.length; i++) {
if(pr[i].innerHTML.length >= 200){
var showLess = pr[i].innerHTML.substring(0, 200);
pr[i].innerHTML = showLess;
}
btn.addEventListener('click', showMore);
function showMore(){
var showMore = pr[i].innerHTML.substring(0, );
pr[i].innerHTML = showMore;
}
}
</script>
智慧大石
森栏
函数式编程
相关分类