3 回答
TA贡献5条经验 获得超3个赞
已改:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form id="fr"></form>
<label for="text_name" form="fr">labels属性:</label>
<input type="text" id="text_name" form="fr" />
<input type="button" id="butt" value="验证" form="fr" onclick="labelsyz()"/>
<script>
function labelsyz(){
var textt = document.getElementById("text_name");
var but = document.getElementById("butt");
var frr = document.getElementById("fr");
if(textt.value == ""){
var tet = document.createElement("label");
tet.setAttribute("for","text_name");
frr.insertBefore(tet,frr.but);
textt.labels[1].innerHTML="请输入姓名";
textt.labels[1].style.color="red";
}
}
</script>
</body>
</html>
TA贡献1064条经验 获得超383个赞
Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
添加回答
举报