javascript - 该网站无法使用加载更多按钮
问题描述
我有 LoadMore 按钮的代码:https ://codepen.io/anon/pen/ZqzPaL
但是当我把它放在网站上时,它就不再起作用了。仅出现更多/更少按钮,但不再显示文本。
我需要说我把脚本放在文件 .js 和 HTML ->
这是使用 id 和 class 的 HTML 代码。
$(document).ready(function () {
size_p = $("#myList p").size();
x=3;
$('#myList p:lt('+x+')').show();
$('#loadMore').click(function () {
x= (x+3 <= size_p) ? x+3 : size_p;
$('#myList p:lt('+x+')').show();
});
$('#showLess').click(function () {
x=(x-3<0) ? 3 : x-3;
$('#myList p').not(':lt('+x+')').hide();
});
});
#myList p{
display:none;
}
#loadMore {
color:green;
cursor:pointer;
padding: 5px 15px;
cursor: pointer;
background: #e8e8e8;
width: 75px;
margin: 5px;
position: relative;
border-radius: 15px;
}
#loadMore:hover
#showLessa:hover
#showLess:hover
{
color:black;
}
#showLess {
color:red;
cursor:pointer;
padding: 5px 15px;
cursor: pointer;
background: #e8e8e8;
position: relative;
border-radius: 15px;
width: 75px;
margin: 5px;
}
<div id="myList">
<p>
Some text here.
</p>
<p>
Second paragraph here.
</p>
</div>
<div id="loadMore">Load more</div>
<div id="showLess">Show less</div>
我需要提一下,段落也在其他类的其他 div 中。
解决方案
推荐阅读
- go - 如何将数据从一种类型复制到具有相同结构的另一种类型?
- matlab - Matlab print() 和 saveas() 覆盖位置输入数据
- javascript - 基于单选按钮的Js计算,以及一些问题
- apache-spark - 为什么我无法连接到 Hive Metastore?
- azure-devops - 如何使用 Linux microsoft 托管代理在 Windows 机器中存储 Azure 管道工件?
- php - 将自定义注册字段扩展到 WooCommerce 中的其他页面
- css - VS Code Extension 自动生成 CSS 代码
- vaadin - Vaadin Flow:删除 PollListener
- python - Pygame敌人不在屏幕上移动
- prolog - 谓词的 Prolog 代码将一个元素散布在列表的第 n 位