點擊提交按鈕後如何讓文本框的文字消失
我希望我的文本框的文本在我點擊提交按鈕後消失這是我的網站的樣子
這是我的 HTML 腳本:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Ask CodeBlox</title> <link rel="stylesheet" href="style.css"> </head> <body> <label>Enter your question:</label><br> <textarea type="text" id="myquestion" placeholder="Your question here"></textarea><br> <input type="text" id="discord" placeholder="Your discord here"></input><br> <button type="button" id="mybutton">Submit</button> <script src="script.js"></script> </body> </html>
這是我的 CSS 腳本:
body { background-color: grey; } #myquestion { background-color: white; border-radius: 1.3mm; border-top: grey; border-left: grey; height: 70mm; width: 100mm; padding: 8px; } #mybutton { background-color: lightblue; border-radius: 1.3mm; border-right: grey; border-bottom: grey; } #discord { background-color: white; border-radius: 1.3mm; border-top: grey; border-left: grey; height: 20px; width: 50mm; }
這是我的 javascript 腳本:
document.getElementById("mybutton").onclick = function(){ var ok = document.getElementById("myquestion").value; var no = document.getElementById("discord").value; const whurl = "I won't reveal my discord webhook token here" const msg = { "content": ok + "n" + no } fetch(whurl, {"method": "POST", "headers": {"content-type": "application/json"}, "body": JSON.stringify(msg)}) }
如果您能幫助我,那將非常有幫助。我希望在單擊提交按鈕後文本框的文本消失並且只顯示佔位符文本。如果可能的話,我想知道如何在焦點腳本上製作一個像文本框這樣的腳本,可能就像當文本框被聚焦時,有一個藍色邊框
回答
點擊提交後,您應該檢查表單是否有效,然後使用:
清除您的文本框document.getElementById("myquestion").value = "";
上一篇
Div 不堆疊,而是重疊