<html>
<body>
<input type="number" id="myNumber" value="2" readonly>
<p>点击按钮查看 number 字段是否为只读。 </p>
<button onclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").readOnly;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>