获取dom元素。 setAttribute(“ size”,“ 50”)不起作用

时间:2019-06-21 00:35:45

标签: javascript dom attributes

我将.settAttribute(“ size”'“ 50”)设置为我的document.getElementById(“ inputDiv”),但不知何故,它无法正常工作。所有其他属性都可以使用。假定此属性用于更改我输入的字符大小。

提前谢谢!

JS:

var input = document.createElement("input");
  input.setAttribute("type", "text");
  input.setAttribute("value", "");
  input.setAttribute("placeholder", "Type your name then press Enter");
  input.setAttribute("maxLength", "4");
  

input.setAttribute(“ size”,“ 50”);

  var parent = document.getElementById("inputDiv");
  parent.appendChild(input);
  parent.style.borderStyle = 'solid';
  parent.style.width = '50%';
  parent.style.margin = 'auto';
  parent.style.borderWidth = '0px 0px .5px 0px';
  parent.style.color = 'black';

1 个答案:

答案 0 :(得分:0)

您可以尝试:

input.setAttribute('maxlength', 50);

请注意,如果您的“大小”表示“字体大小”,则代码应为:

input.style.setProperty('font-size', '50px');