Javascript 如何禁用文本框?

Javascript 如何禁用文本框?,javascript,asp.net-mvc,html,Javascript,Asp.net Mvc,Html,如何在加载页面时禁用文本框? 我的JS <script language="javascript"> function enableDisable(bEnable, textBoxID) { document.getElementById(textBoxID).value = "" document.getElementById(textBoxID).disabled = !bEnable }

如何在加载页面时禁用文本框? 我的JS

<script language="javascript">
        function enableDisable(bEnable, textBoxID) {
            document.getElementById(textBoxID).value = ""
            document.getElementById(textBoxID).disabled = !bEnable

        }
    </script>

功能启用禁用(bEnable,textBoxID){
document.getElementById(textBoxID).value=“”
document.getElementById(textBoxID).disabled=!bEnable
}
我的观点

<input type="checkbox" id="checkBox" onclick="enableDisable(this.checked, 'textBox')">Reason<br />
 <input type="text" id="textBox">
原因

将其默认设置为禁用,然后使用window.onload事件启用它

$(document).ready将在加载HTML文档时启动,但window.onload将等待整个页面(图像、脚本等)加载完毕

小提琴:


window.onload=enableDisable(false,“textBox”);
功能启用禁用(bEnable,textBoxID){
document.getElementById(textBoxID).value=“”
document.getElementById(textBoxID).disabled=!bEnable
}

将其加载为禁用会更容易吗?是的,这就是我需要它的原因是,为什么不将
设置为已将属性设置为禁用
或非HTML5 doctype
禁用=“禁用”
HTML5的代码是什么?这是用于文本输入的
HTML5 disabled属性就是disabled:)请不要在未标记该库的答案中使用jQuery。
    document.querySelector('inout[type="text"]').disabled = true;

    window.onload(function () {
       document.querySelector('inout[type="text"]').disabled = false;
    });
<script language="javascript">
    window.onload =enableDisable(false,"textBox");

    function enableDisable(bEnable, textBoxID) {
        document.getElementById(textBoxID).value = ""
        document.getElementById(textBoxID).disabled = !bEnable

    }
</script>