[英]"input type="submit"" not displaying as a button
我正在嘗試創建一個基於 Web 的測驗應用程序,其中測驗通過表單輸入,然后輸入到文本文件中。 這將分別從文本文件中讀取給用戶。 但是,我的提交按鈕不起作用,我的布局有誤嗎? 然后,我們的想法是逐行讀取文本文件,調用這些行定義的值,並在單獨的網頁上以無線電格式顯示選項。 此外,我希望添加一個名為“添加問題”的新按鈕,它將問題和 3 個答案輸入文本添加到表單底部,使其能夠響應用戶。 我是否必須使整個表單成為一個函數並調用它?
function WriteToFile(passForm) { set fso = CreateObject("Scripting.FileSystemObject"); set s = fso.CreateTextFile(“using theseee / this.txt ", True); var year = document.getElementById('year'); var class = document.getElementById('class'); var topic = document.getElementById('topic'); var title = document.getElementById('title'); var question = document.getElementById('question'); var option1 = document.getElementById('answer1'); var option2 = document.getElementById('answer2'); var option3 = document.getElementById('answer3'); s.writeline(“Title: " + title); s.writeline(“Question: " + question); s.writeline(“Option1: " + answer1); s.writeline(“Option2: " + answer2); s.writeline(“Option3: " + answer3); s.writeline("-----------------------------"); s.Close(); }
<html> <head> <title>Quiz Form</title> <link rel=“stylesheet” href=“TRYstyle.css”> </head> <body> <h3>Quiz form</h3> <table> <form onSubmit=“WriteToFile(this.txt)”> <tr> <td>Title</td> <td><input type=“text” placeholder=“Title” name=“title” id=“title” maxlength=“200”/></td> </tr> <tr> <td>Question</td> <td><input type=“text” placeholder=“Question” name=“question” id=“question” maxlength=“200”/></td> </tr> <tr> <td>Answer</td> <td><input type=“text” placeholder=“Answer” name=“answer1” id=“answer1” maxlength=“200”/></td> </tr> <tr> <td>Answer</td> <td><input type=“text” placeholder=“Answer” name=“answer2” id=“answer2” maxlength=“200”/></td> </tr> <tr> <td>Answer</td> <td><input type=“text” placeholder=“Answer” name=“answer3” id=“answer3” maxlength=“200”/></td> </tr> <tr> <input type=“submit” value=“Submit”> </tr> </form> </table> </body> </html>
您的 HTML 無效。
表單不能是表格元素的子元素,輸入不能是表格行元素的子元素。
只有表格單元格可以是表格行的子項。
此外,您不能使用“
(左雙引號)來分隔屬性值。 只有"
(引號)或'
(撇號)。
使用驗證器。
旁白:一旦你解決了這個問題,你會發現Scripting.FileSystemObject
不能用於 Web 瀏覽器。 您不能使用瀏覽器端 JS 寫入任意文件。
你的雙引號是錯誤的。
這是它的樣子:
<input type=“submit” value=“Submit”>
這是它需要的樣子:
<input type="submit" value="Submit">
由於雙引號,類型無法識別,默認情況下輸入類型為文本。 這就是為什么你有這個問題。
你有多個問題。
class
作為變量名,這是不允許的。 function WriteToFile(passForm) { //No Idea what this is. Wont work in snippet //set fso = CreateObject("Scripting.FileSystemObject"); //set s = fso.CreateTextFile(“using theseee / this.txt ", True); //use the correct quotes var year = document.getElementById('year'); //it's not allowed to use class as a variable var classEl = document.getElementById('class'); var topic = document.getElementById('topic'); var title = document.getElementById('title'); var question = document.getElementById('question'); var option1 = document.getElementById('answer1'); var option2 = document.getElementById('answer2'); var option3 = document.getElementById('answer3'); //use the correct quotes console.log("Title: " + title); console.log("Question: " + question); console.log("Option1: " + answer1); console.log("Option2: " + answer2); console.log("Option3: " + answer3); console.log("-----------------------------"); s.Close(); }
<html> <head> <title>Quiz Form</title> <link rel=“stylesheet” href=“TRYstyle.css”> </head> <body> <h3>Quiz form</h3> <table> <form onSubmit="WriteToFile(this.txt)"> <tr> <td>Title</td> <td><input type="text" placeholder="Title" name="title" id="title" maxlength="200"/></td> </tr> <tr> <td>Question</td> <td><input type="text" placeholder="Question" name="question" id="question" maxlength="200"/></td> </tr> <tr> <td>Answer</td> <td><input type="text" placeholder="Answer" name="answer1" id="answer1" maxlength="200"/></td> </tr> <tr> <td>Answer</td> <td><input type="text" placeholder="Answer" name="answer2" id="answer2" maxlength="200"/></td> </tr> <tr> <td>Answer</td> <td><input type="text" placeholder="Answer" name="answer3" id="answer3" maxlength="200"/></td> </tr> <tr> <td colspan="2"> <input type="submit"> </td> </tr> </form> </table> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.