Uncaught?TypeError:?Cannot?read?property?'0'?of?null<!DOCTYPE?html>?<html>?<head>
?????<meta?charset="UTF-8">?????
?????<meta?name="viewport"?content="width=device-width,?initial-scale=1.0">?????
?????<meta?http-equiv="X-UA-Compatible"?content="ie=edge">?????
?????<title>Document</title>?</head>?
<body>?????
?????<textarea?id="show"?spellcheck="true">#?豬</textarea>?????
?????<input?type="file"?id="file1">?????
?????<input?type="button"?id="btn"?onclick="rec()"?value="轉(zhuǎn)換">?????
?????<script>
??????????????var?filein?=?document.getElementById('file1'),?????????????
??????????????showbox?=?document.getElementById('show');?????????
??????????????filein.addEventListener('change',?function?()?{?????????????
??????????????var?file?=?filein.files[0];?????????????
??????????????var?reader?=?new?FileReader();?????????????
??????????????reader.onload?=?function?(e)?{?????????????????
??????????????????showbox.innerHTML?=?data;?????????????
??????????????};?????????????
??????????????reader.readAsText(file,?'utf-8');?????????
??????????????});?????????
??????????????function?rec()?{?????????????
??????????????var?textarea?=?document.getElementById('show');?????????????
??????????????textarea.innerHTML?=?main(textarea.value);?//可以寫入字符串?????????
??????????????}?????????
??????????????function?main(evt)?{?????????????
??????????????var?char?=?evt.split("\n");?????????????
??????????????var?matchArry;?????????????
??????????????var?html?=?'';?????????????
??????????????var?len?=?char.length;?????????????
??????????????for?(var?i?=?0;?i?<?len;?i++)?{?????????????????
??????????????//數(shù)組儲存模板?????????????????
??????????????matchArry?=?char[i].match(/^#\s/);?//切割成[""]?????????????????
??????????????if?(matchArry[0])?{?????????????????????
??????????????switch?(matchArry[0])?{?//輸入了空的字符串和不匹配字符串則會報錯???
??????????????case?'#?':????????????????????????????
???????????????html?+=?'<h1>'?+?add(char[i].substring(2))?+?'</h1>';?????????????????????????????
???????????????break;?????????????????????????default:?????????????????????????????
???????????????break;?????????????????????}?????????????????
???????????????}?else?{?????????????????????
???????????????html?+=?'<p>'?+?add(char[i])?+?'</p>';?????????????????
???????????????}?????????????
???????????????}?????????????
???????????????return?html;?????????
???????????????}?????????
???????????????function?add(str)?{?????????????
???????????????str?=?str.replace(/\s/g,?' '
???????????????);?????????????
???????????????return?str;?????????
???????????????}?????
????</script>?
</body>?
</html>
這里為什么會報錯?
Ohara_Setsuna
2019-02-21 09:58:43