[英]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.