修改以下JavaScript以在高度小于或等于75px时不追加所需的帮助

修改以下JavaScript以在高度小于或等于75px时不追加所需的帮助,javascript,jquery,append,Javascript,Jquery,Append,我有一个JavaScript函数,它在高于75px的div中添加了一个“more”按钮,因此如果读者想阅读更多内容,他可以单击“more”按钮,div将扩展到其完整大小。我面临的问题是,它添加了一个“更多”按钮,即使div的高度等于或小于75px 因此,现在我需要帮助修改此脚本,使其在div小于或等于75px时不追加[…],但如果div大于75px,则添加“more”按钮 有什么想法吗?Thnx) $(函数(){var adjustheight=75; var moreText=”↓ 更多”;

我有一个JavaScript函数,它在高于75px的div中添加了一个“more”按钮,因此如果读者想阅读更多内容,他可以单击“more”按钮,div将扩展到其完整大小。我面临的问题是,它添加了一个“更多”按钮,即使div的高度等于或小于75px

因此,现在我需要帮助修改此脚本,使其在div小于或等于75px时不追加

[…]

,但如果div大于75px,则添加“more”按钮

有什么想法吗?Thnx)

$(函数(){var adjustheight=75;
var moreText=”↓ 更多”;
var lessText=”↑ 少”;
$(“.more-less.more-block”).css('height',adjustheight).css('overflow','hidden');
$(“.more-less”).append(“

[…]); $(“a.adjust”).text(更多文本); $(“.adjust”).toggle(function(){$(this).parents(“div:first”).find(.more block”).css('height','auto').css('overflow','visible').slideDown(“slow”); $(this).parents(“div:first”).find(“p.continued”).css('display','none'); $(this).text(lessText)},function(){$(this).parents(“div:first”).find(.more block”).css('height',adjustheight).css('overflow','hidden');$(this).parents(“div:first”).find('p.continued”).css('display','block');$(this.text(moreText)}) });

试试这个:

$(函数(){
var调整高度=75;
var moreText=”↓ 更多”;
var lessText=”↑ 少”;
$(“.more-less”).each(函数(){
如果($(此).height()>调整高度){
$(this.append('

[…]

'); } }); $(“.more-less.more-block”).css('height',adjustheight.).css('overflow','hidden'); $(“a.adjust”).text(更多文本); $(“.adjust”).toggle(函数(){ $(this).parents(“div:first”).find(“more block”).css('height','auto').css('overflow','visible').slideDown(“slow”); $(this).parents(“div:first”).find(“p.continued”).css(“display”,“none”); $(this).text(lessText) },函数(){ $(this).parents(“div:first”).find(.more block”).css('height',adjustheight).css('overflow','hidden'); $(this).parents(“div:first”).find(“p.continued”).css('display','block'); $(this).text(moreText) }) });
试试这个:

$(函数(){
var调整高度=75;
var moreText=”↓ 更多”;
var lessText=”↑ 少”;
$(“.more-less”).each(函数(){
如果($(此).height()>调整高度){
$(this.append('

[…]

'); } }); $(“.more-less.more-block”).css('height',adjustheight.).css('overflow','hidden'); $(“a.adjust”).text(更多文本); $(“.adjust”).toggle(函数(){ $(this).parents(“div:first”).find(“more block”).css('height','auto').css('overflow','visible').slideDown(“slow”); $(this).parents(“div:first”).find(“p.continued”).css(“display”,“none”); $(this).text(lessText) },函数(){ $(this).parents(“div:first”).find(.more block”).css('height',adjustheight).css('overflow','hidden'); $(this).parents(“div:first”).find(“p.continued”).css('display','block'); $(this).text(moreText) }) });
添加时出现语法错误,将最后一行更改为});修复了语法错误,但没有执行此操作,它使所有divs 75px都变高,并且没有附加任何

[…]

的内容。添加时给出语法错误,将最后一行更改为});修复了语法错误,但没有执行此操作,它使所有divs 75px都变高,并且没有附加

[…]

。能否提供一个小的(相关的)html示例?内容忽略上面的评论,意外按下回车内容你能提供一个小的(相关的)html样本吗?内容忽略上面的注释,按enter意外输入内容
$(function(){var adjustheight=75;
var moreText="↓ More";
var lessText="↑ Less";
$(".more-less .more-block").css('height',adjustheight).css('overflow','hidden');
$(".more-less").append('<p class="continued">[…]</p><a href="#" class="adjust"></a>');
$("a.adjust").text(moreText);
$(".adjust").toggle(function(){$(this).parents("div:first").find(".more-block").css('height','auto').css('overflow','visible').slideDown("slow");
$(this).parents("div:first").find("p.continued").css('display','none');
$(this).text(lessText)},function(){$(this).parents("div:first").find(".more-block").css('height',adjustheight).css('overflow','hidden');$(this).parents("div:first").find("p.continued").css('display','block');$(this).text(moreText)})
}); 
$(function() {
    var adjustheight = 75;
    var moreText = "↓ More";
    var lessText = "↑ Less";
    $(".more-less").each(function() {
        if ($(this).height() > adjustheight ) {
            $(this).append('<p class="continued">[…]</p><a href="#" class="adjust"></a>');
        }
    });
    $(".more-less .more-block").css('height', adjustheight).css('overflow', 'hidden');


    $("a.adjust").text(moreText);
    $(".adjust").toggle(function() {
        $(this).parents("div:first").find(".more-block").css('height', 'auto').css('overflow', 'visible').slideDown("slow");
        $(this).parents("div:first").find("p.continued").css('display', 'none');
        $(this).text(lessText)
    }, function() {
        $(this).parents("div:first").find(".more-block").css('height', adjustheight).css('overflow', 'hidden');
        $(this).parents("div:first").find("p.continued").css('display', 'block');
        $(this).text(moreText)
    })
});