简体   繁体   English

JavaScript-如何从文件名中分离路径

[英]JavaScript-How To Separate Path from File Name

I need to separate the file path from the file name: (some codes did not work in the past) If the path is www.example.com/hi/test/home.html How would I get just www.example.com/hi/test/ ?我需要将文件路径与文件名分开:(过去某些代码不起作用)如果路径是www.example.com/hi/test/home.html我将如何获得www.example.com/嗨/测试/

You can use substring and lastIndexOf :您可以使用substringlastIndexOf

a = "www.example.com/hi/test/home.html";
b = a.substr(0, a.lastIndexOf('/'));

// b = www.example.com/hi/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javascript-如何在Google Earth中设置kml文件的动画范围 - javascript-how to set the animation range of kml file in google earth javascript-如何打开窗口(来自超链接),然后以5秒的延迟关闭它? - javascript-how to open window (from hyperlink) and then close it with delay of 5 sec? javascript-如何从子窗口启用父窗口的控件 - javascript-how enable controls of a parent window from child window javascript-如何在iframe中检测滚动事件? - javascript-How to detect scroll event in iframe? JavaScript-如何从具有多个节点和数组的Json数组中检查值? - JavaScript-How to check for a value from a Json array having multiple nodes and arrays? 如何使用 JavaScript 从完整路径获取文件名? - How to get the file name from a full path using JavaScript? JavaScript-如何通过单击图像显示/隐藏tr textarea - JavaScript-How to show/hide tr textarea by clicking image javaScript-我们如何将一个eventListener设置为另一个eventListener的从属? - javaScript-how can we set a eventListener as a slave of the other eventListener? Javascript-如何通过Chartist js在饼图上制作叠加标记 - Javascript-How to make overlay tag on the pie chart by Chartist js javascript-如何使用html表单进行面积计算 - javascript-How to do an area calculation with html forms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM