3 回答

TA貢獻(xiàn)5條經(jīng)驗 獲得超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貢獻(xiàn)564條經(jīng)驗 獲得超863個贊
肯定可以響應(yīng)點擊事件的,只是你放到外面就不能那么寫了?frr.insertBefore(tet,but); ?這里會報錯的

TA貢獻(xiàn)1064條經(jīng)驗 獲得超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.
添加回答
舉報