亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 HTML 中的 <input> 標記中設置“最大值”?

如何在 HTML 中的 <input> 標記中設置“最大值”?

www說 2023-07-14 15:41:06
我可以設置“最大值”嗎            <input type="number" step="10" min="10"                   th:max=""                   th:field="*{coins}" required>在 ? 中創建變量        <script>            var wallet = [[${session.student.wallet}]];            var price = [[${item.itemCost}]];            var lowerValue = Math.min(wallet, price);        </script>問題是將 中可見值中較小的一個分配給“max”。
查看完整描述

3 回答

?
心有法竹

TA貢獻1866條經驗 獲得超5個贊

如果你給你的輸入一個id像 (<input id="my-input"...) 這樣的屬性,那么它應該像這樣簡單

document.getElementById("my-input").setAttribute("max", myCalculatedValue):


let

  wallet = 50.00,

  price = 42.00;

const myCalculatedValue = Math.min(wallet, price);


const myInput = document.getElementById("my-input");

myInput.setAttribute("max", myCalculatedValue);

<input id="my-input" type="number" step="10" min="10" />


查看完整回答
反對 回復 2023-07-14
?
達令說

TA貢獻1821條經驗 獲得超6個贊

//default the max to 99

document.getElementById("yourinput").max = 99;


// setMax gets triggered by the button's `onclick` attribute

function setMax() {

   let max = document.getElementById("yourmax").value;

   document.getElementById("yourinput").max = max;

}

<!-- Note that I gave your elements IDs so JS can reference them -->

Default <b>max=99</b> got set when page loaded. Try it below.<br/>

Set max here: <input id="yourmax" value="10"><br/>

Click this button to apply your NEW max: <button onclick="setMax()">Set Max</button></br>

Max gets set on this input: <input id="yourinput" type="number" min="0" style="width:50px;">


查看完整回答
反對 回復 2023-07-14
?
青春有我

TA貢獻1784條經驗 獲得超8個贊

您只需使用 Thymeleaf 即可做到這一點。

<input type="number"
       step="10" min="10"
       th:max="${T(Math).max(session.student.wallet, item.itemCost)}"
       th:field="*{coins}"
       required>



查看完整回答
反對 回復 2023-07-14
  • 3 回答
  • 0 關注
  • 318 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號