我有一个脚本,它会使索引页面只显示最近的5篇博文(由它的cms-repeat类处理)。它工作正常,直到我使用PageLime(在线轻型CMS)添加新的博客文章(它只是复制您随后编辑的文章)。出于某种原因,某些PageLime会杀死脚本,我无法弄清楚原因。我从服务器上抓取了我的html来查看,但仍然没有看到阻止脚本运行的任何内容。
这是主体部分,页脚,脚本代码:
<section class="wrapper blog-page">
<article id="editableBlogPost-1" class="cms-editable cms-repeat clearfix">
<h2>Paper Towl Rolls</h2>
<p>text...</p>
</article><article id="e24450" class="cms-editable cms-repeat clearfix cms-previous-repeat-item-id-editableBlogPost-1" style="display: block;">
<h2>No Storytime today!</h2>
<p>text...</p>
</article><article id="e15438" class="cms-editable cms-repeat clearfix cms-previous-repeat-item-id-editableBlogPost-1" style="display: block;">
<h2>New Resources for Families</h2>
<p>text...</p>
<p><img id="e42608" src="/cms-assets/images/512037.optimized-may12-2-1.jpg" alt="Image of new books at the Logan Family Center, Anxiety, depression, self-esteem and shyness" width="300" height="224" /> <img id="eca5c2" src="/cms-assets/images/107497.optimized-may12-1.jpg" alt="Photo of new family resource books, Anxiety, depression, self-esteem and shyness" width="300" height="224" /></p>
<p> </p>
</article><article id="e3c688" class="cms-editable cms-repeat clearfix cms-previous-repeat-item-id-editableBlogPost-1" style="display: block;">
<h2>Around the World Presenters</h2>
<p>text...</p>
</article><article id="e70d96" class="cms-editable cms-repeat clearfix cms-previous-repeat-item-id-editableBlogPost-1" style="display: block;">
<h2>Do You Have What it Takes?</h2>
<p>text...</p>
</article><article id="e2016e" class="cms-editable cms-repeat clearfix cms-previous-repeat-item-id-e70d96" style="display: block;">
<h2>Ready! Set! School! - <span>Let's Read!</span></h2>
<p><span><img id="e91bf1" src="/cms-assets/images/169742.optimized-april15.jpg" alt="Image of Ready! Set! School! Books used in the Lets Read lesson" width="300" height="225" />text...</span></p>
<p> </p>
</article><article id="e30bb5" class="cms-editable cms-repeat clearfix cms-previous-repeat-item-id-e2016e" style="display: block;">
<h2>Welcome back</h2>
<p><img id="e5597d" src="/cms-assets/images/287627.optimized-april8.jpg" alt="Image of Ready! Set! School! student with book, everybody counts lesson" width="300" height="225" /><span>text...</span></p>
</article>
<input type="button" id="more" value="More">
</section>
<footer class="page-footer">...</footer>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script>
//display next 5 blog posts when "#more" is clicked
size_article = $('.cms-repeat').size();
x=5;
$('.cms-repeat:lt('+x+')').slideDown('slow').show();
$('#more').click(function () {
x= (x+5 <= size_article) ? x+5 : size_article;
$('.cms-repeat:lt('+x+')').slideDown('slow').show();
alert('its working?');
});
//hides "Please enable javascript" message for those with javascript
$("#no-script").hide();
</script>
答案 0 :(得分:0)
问题是PageLime将style =“display:block”作为内联CSS添加到我的大多数文章中,这当然比我的脚本具有更高的特异性。我找不到关于使用Page Lime关闭内联样式的任何内容,所以我只是在另一个之前添加另一个jQuery,以便首先删除样式attr。
$('article').removeAttr("style");