gpt4 book ai didi

javascript - 未选择文件时禁用提交按钮

转载 作者:可可西里 更新时间:2023-10-31 23:32:04 27 4
gpt4 key购买 nike

我试图在未按照在线有效解决方案选择文件时禁用提交按钮。与脚本类型有关吗?

这是我遵循的示例:disable submit button until file selected for upload

<html>
<head>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
$(document).ready(
function(){
$('input:submit').attr('disabled',true);
$('input:file').change(
function(){
if ($(this).val()){
$('input:submit').removeAttr('disabled');
}
else {
$('input:submit').attr('disabled',true);
}
});
});
</script>
</head>

<body>
<form action="#" method="post">

<input type="file" name="fileInput" id="fileInput" />
<input type="submit" value="submit" disabled />


</form>
</body>
</html>

最佳答案

尝试声明 Jquery,因为 Jquery 未包含在内:

  <html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.0.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


<script type="text/javascript">
$(document).ready(
function(){
$('input:submit').attr('disabled',true);
$('input:file').change(
function(){
if ($(this).val()){
$('input:submit').removeAttr('disabled');
}
else {
$('input:submit').attr('disabled',true);
}
});
});
</script>
</head>

<body>
<form action="#" method="post">

<input type="file" name="fileInput" id="fileInput" />
<input type="submit" value="submit" disabled />


</form>
</body>
</html>

关于javascript - 未选择文件时禁用提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16913566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com