无法设置未定义的属性'fontWeight'

时间:2015-12-31 19:26:41

标签: javascript

我试图大胆学生[i] .club,我正在尝试在Student [i] .gender和Student [i] .grade之间放置一个水平空格。每个输入都进入div并显示在其中。如果需要其余代码,我也会在必要时发布。

提前致谢!

    fieldann += Student[i].grade;
    fieldann += Student[i].gender;
    fieldann += Student[i].club;
    fieldann += Student[i].announcement;

    Student[i].grade.style.fontWeight = "900";

    var div = document.createElement("div");
    div.style.width = "20%";
    div.style.height = "100%";
    div.style.background = "white";
    div.style.color = "#202020";
    div.style.border = "1px solid #202020";
    div.align = "center";
    div.style.marginLeft = "40%";
    div.style.fontFamily = "Lato";

    div.innerHTML =

      "<br>" +
      Student[i].club +
      "<br>" +
      "<br>" +
      Student[i].announcement +
      "<br>" +
      "<br>" +
      Student[i].gender +
      Student[i].grade +
      "<br>" +
      "<br>";

    document.body.appendChild(div);

2 个答案:

答案 0 :(得分:0)

Student[i].grade不是HTML DOM元素,因此它没有style属性,因此您无法设置fontWeight属性。

尝试在HTML DOM元素上设置此项,而不是像以下字符串:

div.style.fontWeight = "900";

答案 1 :(得分:0)

在div中添加student [i] .club,然后为其设置字体粗细。

"<br><div id='club'" +
Student[i].club +
"</div><br>" +
"<br>" +
Student[i].announcement +
"<br>" +
"<br>" +
Student[i].gender +
Student[i].grade +
"<br>" +
"<br>";


var club = document.getElementById('club');
club.style.fontWeight="bold";