개발하자/자바스크립트
문자열에서 파일명만 잘라내기
i구야
2015. 2. 17. 11:11
<html>
<head>
<style>
#t1{
width:300px;
}
#t3{
width:300px;
}
</style>
<script>
window.onload=function(){
b.onclick=function(){
var s=t1.value;
var a=s.lastIndexOf("\\");
t2.value=s.substring(a+1);
}
b2.onclick=function(){
var s=t3.value;
var a=s.lastIndexOf("/");
t4.value=s.substring(a+1);
}
}
</script>
</head>
<body>
<input type="text" id="t1" value="D:\dev\Tomcat\webapps\ppp1\a.jsp"><br>
<input type="button" id="b" value="윈도우파일명" onclick=""><br>
<input type="text" id="t2">
<hr>
<input type="text" id="t3" value="/abc/def/b.java"><br>
<input type="button" id="b2" value="리눅스파일명"><br>
<input type="text" id="t4">
</body>
</html>