天天看點

input type="file" 的onchange事件

本文轉載自: https://www.cnblogs.com/hyd309/archive/2008/09/22/1295895.html 作者:hyd309 轉載請注明該聲明。

 <事件.html' target='_self'>input id="FileUpload" type="file" style="width:448px; height: 22px;"

                                    οnclick="return FileUpload_onclick()" οnchange="return FileUpload_onselect()"/>

 <script type="text/javascript" language="javascript">   

        function FileUpload_onselect()

        {

            var path;

            path=document.forms[0].FileUpload.value;      //C:\Documents and Settings\hud\桌面\AddFile.jpg

            var aa;

            aa=path.split('.');

            document.all('TbxName').value=aa[aa.length-1];  //jpg 結果

            var name;

            name=path.split('\\');

            var bb=name[name.length-1];            

            document.all('Tbx_FileName').value=bb.substr(0,bb.indexOf('.'));  //AddFile 結果

        }

    </script>

繼續閱讀