JS的: Cannot read property 'value' of undefined

部分html代码

 <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>随机数据生成</title>
    <link rel="stylesheet" type="text/css" href="css/index.css">
  <script type="text/javascript" src="js/index.js"></script>
</head>
<body>

<textarea rows="1" cols="1"  name="date" class="texta" value=""></textarea>

<script type="text/javascript">
var texta = document.getElementsByTagName("textarea")[0];

start.onclick = function(){
  IntegerDate(peoVal,exceVal,qualVal,unqualVal,texta);
}

外部JS代码

 function IntegerDate(sNum,exce,good,qual,unqual,elements){//注释:总人数,优秀,良好,合格,不合格,要添加的元素
        for(var i = 0;i < sNum;i++){
            if(exce){
                elements.getAttribute("value")  += randomInt(4800,5040) + '\n';
            }
            if(good){
                elements.getAttribute("value") += randomInt(4300,4550) + '\n';
            }
            if(qual){
                elements.getAttribute("value") += randomInt(3100,4180) + '\n';
            }
            if(unqual){
                elements.getAttribute("value") += randomInt(2300,2940) + '\n';
            }
        }
}

错误图片提示

图片说明

错误源代码链接:https://pan.baidu.com/s/1jIu1i2y

忘了说明一件事:被调用的函数是在start.onclick事件中的

你调用这个的地方,代码贴出来看看

function IntegerDate(sNum,exce,good,qual,unqual,elements){这里定义了6个参数

start.onclick = function(){
  IntegerDate(peoVal,exceVal,qualVal,unqualVal,texta);//这里只传了5个参数
}

js调用函数,参数是按顺序接收的!函数有6个参数,调用传了5个,默认对应的是前5个,最后elements应该是undefined

1、你贴的代码跟截图上面的不一样
2、function IntegerDate(sNum,exce,good,qual,unqual,elements){这里定义了6个参数

start.onclick = function(){
IntegerDate(peoVal,exceVal,qualVal,unqualVal,texta);//这里只传了5个参数
}
这个也是有问题的