要限制用户在 JavaScript 中输入数字和小数,可以使用以下方法: 使用HTML的input标签中的"type"属性设置为"number",这将强制输入框只接受数字和小数: <input type="number" />