【问题标题】:undefined is not a function : document.create elementundefined 不是函数:document.create 元素
【发布时间】:2014-05-30 09:58:17
【问题描述】:

我收到系统用户名的错误“未捕获的类型错误:未定义不是函数”。我已经在这里工作了 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);

}

【问题讨论】:

  • 您能否详细说明您的问题。在提供的 sn-p 中没有对 systemUsername 的调用。这个问题和document.createElement有什么关系?
  • 再次使用新帐户? Thisthis 是您的问题吗?使用三个不同的帐户询问?
  • 对不起,我是新来的,但错误在我创建的 systemUsername 元素的 setAttribute 函数上突出显示。
  • 这些不是我的问题吗?
  • 诚实吗?概念相同,“Bernardo O’Higgins”将您连接到这些问题...

标签: javascript undefined


【解决方案1】:

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

alert("tempSU: " + tempSU);

而不是

 alert("tempSU: ".tempSU);

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

【讨论】:

  • 这不会导致错误,它只会提醒undefined。一个修复的地方。
  • 我不明白,改了'.'后到'+'它仍然给我同样的未定义? @Teemu
猜你喜欢
  • 2019-07-21
  • 2020-10-12
  • 2015-10-29
  • 2015-06-05
  • 2019-10-16
  • 2015-06-12
  • 2015-10-16
  • 2013-05-17
  • 1970-01-01
相关资源
最近更新 更多