天天看點

用戶端上傳檔案時,用Javascript(Js)取得檔案名及檔案字尾(File,圖檔)

<SCRIPT LANGUAGE="JavaScript">

<!--

function reAsk(sStr)

{

    return confirm(sStr);

}

function getFileName(o)

{

    var pos=o.value.lastIndexOf("\\");

    return o.value.substring(pos+1);//檔案名

}

function GetFileExt(o)

{

    return o.value.replace(/.+\./,"");

}

//-->

</SCRIPT>

<input type="file" size=38 name="file1" onchange="alert(getFileName(this)+'\n'+GetFileExt(this));"/>