文章出處
文章列表
結合使用string對象中的substr()和lastIndexOf()方法。
當前頁面路徑:file:///C:/Users/Administrator/Desktop/test.html
<pre name="code" class="javascript"><script> var filename=window.location.href; filename=filename.substr(filename.lastIndexOf("/")+1); alert(filename) </script>
結果:test.html
第一行賦值當前的文件路徑。
第二行找到最后一個"/"出現的位置+1即從"/"后一個字符開始算起,返回的值作為substr參數傳入,因為沒有第二個參數,因此substr返回該參數位置開始到字符串末尾的全部字符。
詳細方法介紹請查閱文章javascript知識總匯
文章列表
全站熱搜