第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決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=“”屬性指定了從屬關(guān)系,但是表單元素里的Onclick點擊事件無法用,如果寫到<form></form>內(nèi)就可以用了,請問這是為什么呢?
查看完整描述

3 回答

已采納
?
慕俠8885196

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>


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

TA貢獻(xiàn)564條經(jīng)驗 獲得超863個贊

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

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

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.

查看完整回答
反對 回復(fù) 2016-11-16
  • 3 回答
  • 0 關(guān)注
  • 1448 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號