【问题标题】:Set width no higher than 100%设置宽度不高于 100%
【发布时间】:2013-02-07 06:25:12
【问题描述】:

我如何设置width,使其根据变量值永远不会高于 100%?

var progBarValue = $(this).find('.days-due').text();

$(this).find('.bar').width(progBarValue +"%");

我需要将 width 值限制为最大 100%。

例如:如果 progBarValue 返回 250%,width 仍将是 100%。

【问题讨论】:

  • 你试过什么?您所要做的就是检测progBarValue 是什么,如果它大于100,则将其设置为100

标签: jquery


【解决方案1】:

我认为您将不得不修改变量本身,因为宽度属性可以> 100%。

var progBarValue = $(this).find('.days-due').text();
progBarValue = progBarValue > 100 ? 100 : progBarValue;
$(this).find('.bar').width(progBarValue +"%");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-11
    • 2016-08-09
    • 2015-02-04
    • 2014-05-26
    • 1970-01-01
    • 2016-10-08
    • 2018-01-15
    • 2021-05-08
    相关资源
    最近更新 更多