为什么这行JS代码返回错误"无法设置属性...未定义"?
String nt = df.format(dates);
我正确引用了div元素的id。
document.forms["myForm"]["english_error"].textContent = "English sentence is required";
答案 0 :(得分:1)
仅映射表单控件,基本上只映射<input>
,<textarea>
,<select>
标记:
var sentence = document.forms["myForm"]["english"];
<input>
标记是否有效:
document.forms["myForm"]["english_error"].textContent = "English sentence is required";
english_error
是正常的<div>
因此不起作用,您必须使用:
document.getElementById("english_error").textContent = "English sentence is required";
还有班级名称:
document.getElementsByClassName("val_error")[0].textContent = "English sentence is required";