我正在尝试验证用户是否在未选择文件时单击导入按钮以及用户是否选择非 csv 文件。请告知,它目前不验证任何东西。即使我已经将验证放在提交按钮上。请指教,谢谢
这是代码:
@(Html.Kendo().Upload()
.HtmlAttributes(new { @Style = "align:center; font-size:12px; background-color:#3399FF" })
.Name("FileUpload")
.Multiple(false)
.Events(ev => ev.Success("onSuccess"))
)
<script type="text/javascript">
$(document).ready(function () {
$(".k-button.k-upload-button").after(' <input type="submit" id="btnSubmit" value="Import" style="height:31px; font-size:14px; background-color:#3399FF" class="k-button" />');
$('#btnSubmit').click(function (e){
var theFileElement = document.getElementById("FileUpload");
filename = theFileElement.value;
if(filename.length == 0)
{
alert("Please select a csv file to import");
return false;
}
else if (!/\.csv$/i.test(filename)) {
alert("Please upload csv file only");
return false;
}
return true;
});
});
</script>