文章出處

結合使用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知識總匯


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()