我有一个单选按钮,如果它被选中,我需要检查文件是否被上传。
如果选择了 "其他 "单选按钮,红色的信息就会显示,这是正确的。
但是如果不显示,也还是显示同样的信息,但是是黑色的。
如果不选择 "其他",我希望它不显示黑色信息(完全不显示信息)。我知道我目前的代码不完整。
另外,我目前写的是希望'提交'按钮在上传文件之前是不透明的,以防选择'其他',但没有反应,也没有被禁用。
$("#otherradiobutton").on('click', function () {
let hasError = false;
let color = 'red';
if ($("annotatedsamplefile").val() == null){
alert('null');
$('#emptysamplefileerror').show();
$('#emptysamplefileerror').css('color', color);
hasError = true;
}
else {
$('#emptysamplefileerror').hide();
}
$('button[type="submit"]').prop('disabled', hasError);
})
和
<input type="file" name="annotatedsamplefile" id="annotatedsamplefile" accept=".xlsx, .xls, .csv">
<span id="emptysamplefileerror"><b>Please upload a sample annotated file if you chose <b>Other</b> </b></span>
使用 "其他 "单选按钮 style="display:none;
在下面的工作。
<span id="emptysamplefileerror" style="display:none;">Please upload a sample annotated file if you chose <b>Other</b></span>