如何阻止脚本运行

时间:2013-02-01 03:11:31

标签: javascript jquery

我一直试图解决这个问题,并且可能第五次问同样的问题。 有一天,我会放松心情。无论如何

这就是我正在做的事情

我有四个标签。选项卡中的内容是动态生成的。有时他们很长,并且页面布局混乱。所以我这样做是为了限制它们达到540个字符

<script>
$(function(){
    var myDivThree = $('#pdpTab6');
    myDivThree.html(myDivThree.html().substring(0,540));
    $(myDivThree).append('<div id="readThree">Read More</div>');
    //this is what I am doing to show the extra content
    $('#readThree').click(function(){
        $('#popThree').show();
    });
    $('.closePop').click(function(){
        $('#popThree').fadeOut();
    })
});
</script>

奇怪的是如果一个标签包含少于540个字符,我看到更多阅读两次。我希望如果一个标签包含少于540个字符,则根本不运行该脚本。我白天做梦还是可行?

1 个答案:

答案 0 :(得分:0)

<script>
$(function(){
    var myDivThree = $('#pdpTab6');
    if (myDivThree.html().length>540){
        myDivThree.html(myDivThree.html().substring(0,540));
        $(myDivThree).append('<div id="readThree">Read More</div>');
       //this is what I am doing to show the extra content
    }

    $('#readThree').click(function(){
        $('#popThree').show();
    });
    $('.closePop').click(function(){
        $('#popThree').fadeOut();
    })
});
</script>
相关问题