<button type="button" data-value="100" id="btn">BUTTON</button>
const btnVal = $("#btn").data("value");
console.log(typeof btnVal); -- "btnVal" type is number
我想將值作為字串獲取,但是還有其他方法可以使用 toString() 嗎?
uj5u.com熱心網友回復:
只需將其作為屬性讀取即可。像這樣:
const btnVal = $("#btn").attr("data-value");
console.log(typeof btnVal);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<button type="button" data-value="100" id="btn">BUTTON</button>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/378066.html
標籤:javascript 查询
上一篇:當單個表單中有多個下拉欄位時,如何在JQuery中為select標記參考選擇器?
下一篇:選擇欄位:獲取選定值的對應值
