亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

HTML5表單form屬性?

HTML5表單form屬性?

<!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,but); textt.labels[1].innerHTML="請輸入姓名"; textt.labels[1].style.color="red"; } } </script> </body> </html>如上代碼所示,我將表單元素放在form表單外面了,但是用了form=“”屬性指定了從屬關系,但是表單元素里的Onclick點擊事件無法用,如果寫到<form></form>內就可以用了,請問這是為什么呢?
查看完整描述

3 回答

已采納
?
慕俠8885196

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>


查看完整回答
反對 回復 2016-11-16
?
蜂之谷

TA貢獻564條經驗 獲得超863個贊

肯定可以響應點擊事件的,只是你放到外面就不能那么寫了?frr.insertBefore(tet,but); ?這里會報錯的

查看完整回答
反對 回復 2016-11-16
?
田心楓

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.

查看完整回答
反對 回復 2016-11-16
  • 3 回答
  • 0 關注
  • 1450 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號