Undefined不是一个函数:document.创建元素

undefined is not a function : document.create element

本文关键字:函数 document 创建 元素 一个 Undefined      更新时间:2023-09-26

我得到这个错误'未捕获的TypeError:未定义的不是一个函数'为systemUsername。我已经在这个超过2个小时了,我不明白这是怎么定义的?

function systemUsername()
{
/*consists of the first
alphabetic characters found in the Family name, street address, Given name; the numerical day of the
month; and the numerical seconds field of the time of submission. E.g.: A user registers with name
Bernardo O’Higgins, address 213 Liberator St, at 12:31:16 on 25 April 2014. His system username is
OLB2516*/
var systemUsername = document.createElement("systemUsername");
var lastname = document.forms["userinfo"]["famName"].value;
var Address = document.forms["userinfo"]["address"].value;
//var withNoDigits = address.replace(/[0-9]/g, '');
var firstname = document.forms["userinfo"]["firstName"].value;
var dateStamp = new Date();
var dayNum = dateStamp.getDate();
var Seconds = dateStamp.getSeconds();
if (dayNum<10)
{
    var x = '0';
    dayNum = x + dayNum;
}
    alert(dayNum);
if (Seconds<10)
{
    var x = '0';
    Seconds = x + Seconds;
}
    alert(Seconds);
var tempSU = lastname.charAt(0)+Address.charAt(0)+firstname.charAt(0)+dayNum.charAt(0)+dayNum.charAt(1)+Seconds.charAt(0)+Seconds.charAt(1);
systemUsername.setAttribute("type", "hidden");
systemUsername.setAttribute("name", "systemName");
systemUsername.setAttribute("value", "tempSU");
document.getElementById("userinfo").appendChild(systemUsername);
alert("tempSU: ".tempSU);

}

试试这个,用+代替.进行连接

alert("tempSU: " + tempSU);

代替

 alert("tempSU: ".tempSU);

演示:http://jsfiddle.net/5yXAL/