繁体   English   中英

绝对值 Javascript

[英]Absolute value Javascript

我正在尝试在 otree(使用 PyCharm)上创建一个 MPL(多个价目表)。 对于我的一个应用程序(WTP),我在 html“文件夹”(使用 Javascript)上写了这段代码:

{% if choice.0 > 0 %}  If you are paid {{choice.0}} points for this item, would you accept?
    {% elif choice.0 == 0 %}
        If you are paid {{choice.0}} points for this item, would you accept?
    {% elif choice.0 < 0 %}
        If you have to pay {{choice.0}} points for this item, would you accept?
    {% endif %}

在 pages.py 上定义的不同选择:

  self.participant.vars['choices'] = [
        [+30, "choice1", "choice1-yes", "choice1-no"],
        [+20, "choice2", "choice2-yes", "choice2-no"],
        [+10, "choice3", "choice3-yes", "choice3-no"],
        [0, "choice4", "choice4-yes", "choice4-no"],
        [-10, "choice5", "choice5-yes", "choice5-no"],
        [-20, "choice6", "choice6-yes", "choice6-no"],
        [-30, "choice7", "choice7-yes", "choice7-no"],

但是,我希望参与者屏幕上的所有数字都没有“减号”。 如何修改我的 Javascript 代码 st -10 变为 10,-20 变为 20,-30 变为 30。

谢谢!

使用Math.abs()

Math.abs(-30) // 30

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM