Javascript Readmore.js脚本
我有一个关于readmore.js脚本的快速问题 代码如下:Javascript Readmore.js脚本,javascript,jquery,Javascript,Jquery,我有一个关于readmore.js脚本的快速问题 代码如下: $('article').readmore({maxHeight: 240}); 它以html文章标记为目标,但如何更改为只以一篇文章为目标 谢谢 编辑 这是在html的末尾 $(“#信息”)。阅读更多({ moreLink:“, 最大高度:390, 后记:功能(触发器、元素、扩展){ 如果(!expanded){//则单击了“关闭”链接 $('html,body').animate({scrollTop:element.off
$('article').readmore({maxHeight: 240});
它以html文章标记为目标,但如何更改为只以一篇文章为目标
谢谢
编辑
这是在html的末尾
$(“#信息”)。阅读更多({
moreLink:“,
最大高度:390,
后记:功能(触发器、元素、扩展){
如果(!expanded){//则单击了“关闭”链接
$('html,body').animate({scrollTop:element.offset().top},{duration:100});
}
}
});
$('article').readmore({maxHeight:240});
看起来readmore使用了一个类似jQuery的框架和CSS选择器
要针对特定的文章,只需优化选择器。例如,如果您的HTML中有:
<article id="my-id">...</article>
因为这是CSS选择器,它以页面上具有特定ID的元素为目标。您可以使用以下函数 JS代码
//read more or less
function showMoreOrLess(thisObj,bonusContent){
var caption = thisObj.innerHTML;
//alert(caption);
if ( caption == "Read more" ) {
document.getElementById(bonusContent).style.display = "inline";
thisObj.innerHTML = "Read less";
} else {
document.getElementById(bonusContent).style.display = "none";
thisObj.innerHTML = "Read more";
}
}
main text here...
<a class="read" onclick="showMoreOrLess(this,'moreS1');">Read more</a>
<span id="moreS1" style="display:none">
whatever text you need to put here...
</span>
HTML代码
//read more or less
function showMoreOrLess(thisObj,bonusContent){
var caption = thisObj.innerHTML;
//alert(caption);
if ( caption == "Read more" ) {
document.getElementById(bonusContent).style.display = "inline";
thisObj.innerHTML = "Read less";
} else {
document.getElementById(bonusContent).style.display = "none";
thisObj.innerHTML = "Read more";
}
}
main text here...
<a class="read" onclick="showMoreOrLess(this,'moreS1');">Read more</a>
<span id="moreS1" style="display:none">
whatever text you need to put here...
</span>
这里的主文本。。。
阅读更多
无论你需要在这里放什么文字。。。
这个问题与Readmore本身无关,但您只是关于jquery选择器。您如何确定您要针对的特定文章?当前,$('article')
选择每个文章
元素。您的特定文章是否有id
?与其他文章不同的是,如果它不起作用,那么您必须向我们展示更多的内容。例如,如果您的
标记非常高,例如在文档的
中,而
是在它下面定义的,则可能会失败。另一种情况是,如果你把上面的…
误认为是文字字符,而不是“在这里填写所需内容”的人工指令;如果我们只能回答“是”、“否”、“否”、“是”,我们就无法有效地解决问题……我更新了问题,感谢您抽出时间回答克里斯,非常感谢!恐怕没有带id标签的快乐。但是有了类标签,它就可以工作了!再次感谢你的帮助!