标记稍后通过Javascript显示的隐藏内容
我有以下几段:标记稍后通过Javascript显示的隐藏内容,javascript,jquery,html,Javascript,Jquery,Html,我有以下几段: <p>Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing <a>READ MORE</a> firm communication
<p>Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing <a>READ MORE</a> firm communications and setting up interviews.</p>
<p>Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing firm communications and setting up interviews.</p>
<p>Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing <a class="content-hider">READ MORE</a><span class="extra-content" style="display:none;"> firm communications and setting up interviews.</span></p>
您的组织是否为危机做好了准备?大多数专业服务公司都有与媒体打交道的流程。我们已经建立了发送新闻稿、发布阅读更多公司通讯和安排采访的系统
您的组织是否准备好应对危机?大多数专业服务公司都有与媒体打交道的流程。已经有了发送新闻稿、发布公司通讯和安排采访的系统
在我读到更多内容的地方,我希望隐藏所有后续文本,然后在我使用Javascript激活链接时显示。我本来打算在该段落的其余部分加上class=“hiddencontent”之类的SPAN,但现在我意识到,既然我有了第一段的其余部分,再加上整个第二段,那么推荐的标记方法是什么?显然,一个跨度元素不能是两个不同段落的一部分
请注意,此页面上将有多个这样的“阅读更多”段落,因此我不能只做一个全面的$('.hiddencontent').show();在页面中的所有内容上
谢谢 我只需将相关段落包装在一个元素中,比如div,创建一个隐藏类(例如,hidden),并将该类应用于您想要隐藏的任何内容。最简单的方法是将链接后面的文本包装在一个范围内,并将隐藏类应用于该范围及其后面的段落,如下所示:
<div>
<p>Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing <a>READ MORE</a><span class="hidden"> firm communications and setting up interviews.</span></p>
<p class="hidden">Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing firm communications and setting up interviews.</p>
</div>
试试这样的方法:
<p>Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing <a>READ MORE</a> firm communications and setting up interviews.</p>
<p>Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing firm communications and setting up interviews.</p>
<p>Is your organization prepared for a crisis? Most professional service firms have a process for dealing with the media. There are systems in place for sending out press releases, issuing <a class="content-hider">READ MORE</a><span class="extra-content" style="display:none;"> firm communications and setting up interviews.</span></p>
具有删除超链接直到重新加载页面的效果,如果这是您想要的效果?尝试我的功能并根据您的需要修改它(注意:您需要jquery)
$(文档)。在('单击',“.read\u more\u link”,函数()上{
var read_m_id=$(this.attr(“rel”);
$(“#第二部分”+read#m_id).fadeIn();
$(this.hide('fast'))
});
将hiddencontent跨距放在第一段的其余部分和第二段的所有部分。小心无意中将其应用于所有超链接!:S@ne1410s-是的,很明显。像
这样的类会让事情变得更简单。只有当你知道的时候才明显!完美的谢谢你的帮助,Javascript是一个额外的奖励!是的,我还隐藏了阅读更多链接。
<?php
$text="your_text";// your text
$post_id="1";// a unique number to make sure that when a read more link is clicked all the .second parts are not shown,only the one which has the same number will be shown.
function read_more($text,$post_id)
{
if(strlen($text) > 150)//if the text is greater than 150 characters
{
//cut the string in 2 parts
$first_part = substr($initial_cap_sin, 0, 150);//first part
$second_part = substr($initial_cap_sin,150);//second part
$final_text = ' <!---first part-------->
<span class="first_part">'.$first_part.'</span>
<!----second part------>
<span class="second_part" id="second_part'.$post_id.'">'.$second_part.'</span>
<!----read more link--->
<span class="read_more_link" rel="'.$post_id.'">... Read More</span>';
}
else
{
$final_text=$text;// else if the text is not greater than 150 characters dont do any thing
}
}
echo read_more($text);//send the text to the readmore function for processinf
?>
<script>
$(document).on('click',".read_more_link",function(){
var read_m_id = $(this).attr("rel");
$("#second_part"+read_m_id).fadeIn();
$(this).hide('fast')
});
</script>