Javascript 如何停止脚本运行
我一直在想这个问题,可能第五次问同样的问题了。 总有一天我会释怀的。无论如何 这就是我正在做的 我有四个标签。选项卡中的内容是动态生成的。有时它们很长,会扰乱页面布局。所以我这样做是为了限制他们最多540个字符Javascript 如何停止脚本运行,javascript,jquery,Javascript,Jquery,我一直在想这个问题,可能第五次问同样的问题了。 总有一天我会释怀的。无论如何 这就是我正在做的 我有四个标签。选项卡中的内容是动态生成的。有时它们很长,会扰乱页面布局。所以我这样做是为了限制他们最多540个字符 <script> $(function(){ var myDivThree = $('#pdpTab6'); myDivThree.html(myDivThree.html().substring(0,540)); $(myDivThree).appe
<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>
$(函数(){
var myDivThree=$('pdpTab6');
html(myDivThree.html().substring(0540));
$(myDivThree.append('readmore');
//这就是我正在做的,以显示额外的内容
$('#readThree')。单击(函数(){
$('poptree').show();
});
$('.closePop')。单击(函数(){
$('poptree').fadeOut();
})
});
奇怪的是,如果一个选项卡包含的字符少于540个,我会看到它读了两次以上。如果一个选项卡包含少于540个字符,我宁愿不运行脚本。我是在做白日梦还是可行?
<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>
$(函数(){
var myDivThree=$('pdpTab6');
如果(myDivThree.html().length>540){
html(myDivThree.html().substring(0540));
$(myDivThree.append('readmore');
//这就是我正在做的,以显示额外的内容
}
$('#readThree')。单击(函数(){
$('poptree').show();
});
$('.closePop')。单击(函数(){
$('poptree').fadeOut();
})
});
能否添加一个if(myDivThree.html.length>540)
语句类型?修复myDivThree.html()。当时我不是在做白日梦:-)里卡多洛曼不太可能。他想要少于540个字符。不小于或等于。@WojciechBednarski“如果选项卡包含少于540个字符,我宁愿不运行脚本”
。因此,如果有540必须运行。