2
function aloop()
{
    var count = 0;
    var stars;

    stars = newCost;
    document.eMarkForm.dangerRange.value =  document.eMarkForm.dangerRange.value + "\n" + newCost + " " ;

    for (var count = 1; count <= stars; count = count + 1)
    {
        document.eMarkForm.dangerRange.value = document.eMarkForm.dangerRange.value + "*" ;
    }
}

所以我计算了一个名为 newCost 的金额,我希望它显示在我的 dangerRange 文本字段中,值旁边有一个 *。但是,我希望每 10 个 newCost 出现 1 个 *。我怎样才能做到这一点?

4

1 回答 1

0

在“for”循环中,将 'count' 增加 10:count = count + 10并将比较运算符更改为 '<': count < stars。如果您总是想要至少一颗星,请从 0 开始“计数”,否则从 10 开始。

于 2012-11-30T06:23:03.813 回答