input屬性設置type="number"之后, 仍可輸入e, E, -, + 的解決辦法


<el-input v-model="scope.row.variables.leaderbuweiscores.score" @keyup.native="changeInput(scope.row)" onmousewheel="return false;" οninput="value=value.replace(/[^\d.]/g,'')" type="number" :disabled="scope.row.leaderBumenRoleId != user.roleId || notEnd">

  

原因:

    e在數學上代表2.71828,所以它也還是一個數字

    在網上找了很多方案發現用起來都不是很方便, 最后用正則來做是比較簡單的

解決方案:

    直接在input標簽內加一個屬性 οninput="value=value.replace(/[^\d]/g,'')"  即可完美解決

    如果有其他輸入需求, 直接修改正則表達式即可, 例:

        允許輸入小數: οninput="value=value.replace(/[^\d.]/g,'')"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM