Returns the name of the file represented by a File object. For security reasons, the path is excluded from this property.

句法

var name = file.name;
					

A string, containing the name of the file without path, such as "My Resume.rtf".

范例

<input type="file" multiple onchange="processSelectedFiles(this)">
					
function processSelectedFiles(fileInput) {
  var files = fileInput.files;
  for (var i = 0; i < files.length; i++) {
    alert("Filename " + files[i].name);
  }
}
					

Try the results out below:

规范

规范 状态 注释
文件 API
The definition of 'name' in that specification.
工作草案 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
名称 Chrome 13 Edge 12 Firefox 3.6 IE 10 Opera 16 Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: