为了账号安全,请及时绑定邮箱和手机立即绑定

这里为什么会报错?

这里为什么会报错?

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="转换">           <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++) {                                //数组储存模板                                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, '&nbsp;'                );                             return str;                         }          </script>  </body>  </html>
查看完整描述

1 回答

?
Ohara_Setsuna

TA贡献2条经验 获得超1个赞

求大神带飞

查看完整回答
反对 回复 2019-02-21
  • 1 回答
  • 0 关注
  • 885 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信