nks*_*420 5 javascript asp.net file-upload
我将使用asp.net中的文件上传控件上传文件.现在我想使用java脚本获取没有扩展名的文件名.我想验证文件名应该只是整数格式
$(function () {
$('#<%=File1.ClientID %>').change(function () {
var uploadcontrol = document.getElementById('<%=File1.ClientID%>').value;
})
})
Run Code Online (Sandbox Code Playgroud)
试试这个:
$('#test').change(function() {
//something like C:\fakepath\1.html
var fpath = this.value;
fpath = fpath.replace(/\\/g, '/');
var fname = fpath.substring(fpath.lastIndexOf('/')+1, fpath.lastIndexOf('.'));
console.log(fname);
});
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/rooseve/Sdq24/
您可以根据点('.')的最后一个实例将其拆分
var uploadcontrol = document.getElementById('<%=File1.ClientID%>').value;
uploadcontrol = uploadcontrol.split('.')[uploadcontrol.split('.').length - 2];
Run Code Online (Sandbox Code Playgroud)
但,
这仅对简单情况有效... How to get the file name from a full path using JavaScript?给出了更好的通用答案 ?
在通用解决方案中处理这些事情
| 归档时间: |
|
| 查看次数: |
19355 次 |
| 最近记录: |