我最近开始使用JavaScript进行编码,并且正在为课程项目执行此操作。所以,我想要做的是从textarea中获取拼接数据(以这种形式:artist | album | year | genre | rating),然后对其进行处理,以便在表单后将它们放入表中。
<form name="viewform" enctype="text/plain">
<table class="center" id="table0" name="table0">
<!-- Here is the textarea and an onClick activated button -->
</table>
<table class="center" id="table1" name="table1">
<tr>
<th>Artist</th><th>Album</th><th>Year</th><th>Genre</th><th>Rating</th>
</tr>
</table>
<script type="text/javascript">
// viewScript() is for processing input from a textarea and setting it into HTML tables
function viewScript() {
var textArea = String(document.getElementById('textarea'));
var arrayTextarea = textArea.split('\n'); // Every line becomes a string element in the array
var arrayTextareaLength = arrayTextarea.length; // Count number of elements in arrayTextarea
var table = document.getElementById('table1');
var i, x;
for (i=0; i <= arrayTextareaLength; i++) {
var miniArray = arrayTextarea[i].split('|'); // Each string element in arrayTextarea becomes split into elements in miniArray. Each loop, miniArray changes to the next line
/* Below is a loop to insert miniArray[i] into table1 */
}
}
}
</script>
</form>
问题出在for循环打开后的行中。开发人员的控制台告诉我,它无法读取未定义的属性“拆分”。我做错了什么?