我試圖禁用在線工作解決方案後未選擇文件時提交按鈕。這與腳本類型有關嗎?未選擇文件時禁用提交按鈕
這是我遵循的例子: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庫? –
你的代碼工作正常 - http://jsfiddle.net/fUvvb/。您在這裏沒有包含jQuery庫,但是 – lifetimes
嗨,選擇文件時發生了什麼?您是否希望按鈕僅在按下按鈕或文件被真正選中時啓用? – Jaay