jQuery.text().length()与for循环一起使用
我希望我的措辞正确。我使用jQuery函数根据文本的长度在不同的跨距内调整文本大小。到目前为止还不错,但它是所有值的总和,我需要它来单独检查它们,并根据最长的值来调整大小。问题在于所讨论的跨度是用for循环呈现的,所以难怪它会组合这些值。一次显示的跨度不会超过三个 有人能帮忙吗jQuery.text().length()与for循环一起使用,jquery,text,for-loop,resize,Jquery,Text,For Loop,Resize,我希望我的措辞正确。我使用jQuery函数根据文本的长度在不同的跨距内调整文本大小。到目前为止还不错,但它是所有值的总和,我需要它来单独检查它们,并根据最长的值来调整大小。问题在于所讨论的跨度是用for循环呈现的,所以难怪它会组合这些值。一次显示的跨度不会超过三个 有人能帮忙吗 <script type="text/javascript"> var $quote = $(".check_in_footer .last_check.units"); var $numWords = $q
<script type="text/javascript">
var $quote = $(".check_in_footer .last_check.units");
var $numWords = $quote.text().length;
jQuery(document).ready(function($) {
alert($numWords);
$(function() {
if (($numWords >= 1) && ($numWords < 6)) {
$quote.css("font-size", "400%");
}
else if (($numWords >= 7) && ($numWords < 8)) {
$quote.css("font-size", "600%");
}
else {
$quote.css("color", "#ff0000");
}
});
});
var$quote=$(“.check_in_footer.last_check.units”);
var$numWords=$quote.text().length;
jQuery(文档).ready(函数($){
警报($numWords);
$(函数(){
如果(($numWords>=1)和($numWords<6)){
$quote.css(“字体大小”,“400%”);
}
如果($numWords>=7)和($numWords<8)){
$quote.css(“字体大小”,“600%”);
}
否则{
$quote.css(“颜色”、“ff0000”);
}
});
});
$(“.check\u in\u footer.last\u check.units”)。每个(函数(){
var$numWords=$(this).text().length;
如果(($numWords>=1)和($numWords<6)){
$(this.css(“字体大小”,“400%”);
}
如果($numWords>=7)和($numWords<8)){
$(this.css(“字体大小”,“600%”);
}
否则{
$(this.css(“color”,“#ff0000”);
}
});
您需要删除代码的前两行(就在“打开脚本”标记下面)。
我没有检查其余的代码,只是实现了循环逻辑。问题中的for循环在哪里?我没有发布它,因为我觉得它与我的问题无关。我只是想知道如何将jQuery函数应用于循环元素。
$(".check_in_footer .last_check.units").each(function () {
var $numWords = $(this).text().length;
if (($numWords >= 1) && ($numWords < 6)) {
$(this).css("font-size", "400%");
}
else if (($numWords >= 7) && ($numWords < 8)) {
$(this).css("font-size", "600%");
}
else {
$(this).css("color", "#ff0000");
}
});