Javascript 在文档连接到浏览器之前,如何禁用“提交”按钮?

Javascript 在文档连接到浏览器之前,如何禁用“提交”按钮?,javascript,jsp,Javascript,Jsp,我希望用户在允许用户单击“提交”之前在浏览器中附加文件。我想在文件未附加时禁用submit按钮,在使用javascript附加文件时启用submit按钮 Jsp: 1)将“禁用”属性添加到按钮中 2) 添加函数到 <input id='img' type='file' onchange='attachment(event)'/> 3) 为该事件添加脚本 <script> function attachment(evt){ var files

我希望用户在允许用户单击“提交”之前在浏览器中附加文件。我想在文件未附加时禁用submit按钮,在使用javascript附加文件时启用submit按钮

Jsp:


1)将“禁用”属性添加到按钮中
2) 添加函数到

<input id='img' type='file' onchange='attachment(event)'/>

3) 为该事件添加脚本

<script>
    function attachment(evt){
        var files = evt.target.files;
        //code for checking if evt have any files
        //if yes then remove "disabled" from the button
        //if no then exit if statement and do nothing
    }
</script>

功能附件(evt){
var files=evt.target.files;
//用于检查evt是否有任何文件的代码
//如果是,则从按钮上删除“禁用”
//如果否,则退出if语句,不执行任何操作
}
类似的方法也应该奏效。。
希望这能有所帮助并提供一些想法:)

当点击提交链接(应该是一个按钮)时,从可访问性的角度来看,onmouseover并不是很好,最好避免这样的事件侦听器。
<script>
    function attachment(evt){
        var files = evt.target.files;
        //code for checking if evt have any files
        //if yes then remove "disabled" from the button
        //if no then exit if statement and do nothing
    }
</script>