html javascript讀取 文件內容

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件讀取</title>
</head>
<body>
    <input type="file">

<script>

function get_html_css_fun( info ){
    info = info.replace("kd.Reg(\"PK_機構單位\", {","")
    var last = info.lastIndexOf("});")
    info = info.substring(0,last)
    return info
}


function get_html(info){
    //console.log(info)

    start = info.indexOf("html:[")
    end = info.indexOf("css:[")
    //console.log(start)
    //console.log(end)
    info = info.substring( (start+"html:[".length ), (end- "css:[".length - "],".length ) )


    return info
}


function get_css(info){
    //console.log(info)
    start = info.indexOf("css:[")

    end = info.indexOf("fun: function() {")
    console.log(start)
    console.log(end)
    info = info.substring( (start+"css:[".length ), (end    ) )

    last  = info.lastIndexOf("],")
    info = info.substring(0, last)


    return info

}


function get_fun(info){
    start = info.indexOf("fun: function() {")
    last  = info.lastIndexOf("}")
    info = info.substring(start + "fun: function() {".length, last)
    return info
}


    var input = document.querySelector("input")
    input.onchange=function(){

        /*
        查看this裏的屬性
        for(var key in this) {
            console.log(this[key]);
        }
        */
        // 獲取文件
        var files = this.files[0];

        // 開始讀取,創建讀取器
        var reader = new FileReader();

        // 開始讀取
        reader.readAsText(files)

        // 文件讀取完成後,獲取文件內容
        reader.onload = function() {
            // 獲取結果
            //console.log(reader.result);
            var todo_text = reader.result ;

            var html_css_fun = get_html_css_fun( todo_text )
            //console.log(html_css_fun)


            var text_html = get_html( html_css_fun );
            console.log("------------------------text_html------------------------")
            console.log(text_html)

            
            var text_css = get_css( html_css_fun );
            console.log("------------------------text_css------------------------")
            console.log(text_css )


            var text_fun = get_fun( html_css_fun );
            console.log("------------------------text_fun------------------------")
            console.log(text_fun )
        }                  
    }
</script>
</body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章