<html>
<body>
<input type="number" id="myNumber" value="2">
<p>点击按钮设置 number 字段为只读。</p>
<p><strong>提示:</strong> 为了查看效果,你可以在点击按钮前或者后在输入框中输入数值。</p>
<button onclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myNumber").readOnly = true;
}
</script>
</body>
</html>