简体   繁体   English

“输入类型=“提交””不显示为按钮

[英]"input type="submit"" not displaying as a button

I am trying to create a web-based quiz application where the quiz is inputted through a form and then inputted into a text file.我正在尝试创建一个基于 Web 的测验应用程序,其中测验通过表单输入,然后输入到文本文件中。 this will then be read from the text file to the user separately.这将分别从文本文件中读取给用户。 My submit button is not working however, have i laid it out wrong?但是,我的提交按钮不起作用,我的布局有误吗? The idea is to then read the text file line by line calling on values define by these lines, and displaying the options in radio format on a seperate webpage.然后,我们的想法是逐行读取文本文件,调用这些行定义的值,并在单独的网页上以无线电格式显示选项。 Also, i wish to add a new button called "add question" which adds the question and 3 answer input texts to the bottom of the form, making it responsive to the user.此外,我希望添加一个名为“添加问题”的新按钮,它将问题和 3 个答案输入文本添加到表单底部,使其能够响应用户。 Would i have to make the whole form a function and call on it?我是否必须使整个表单成为一个函数并调用它?

 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>

Your HTML is invalid.您的 HTML 无效。

A form can't be a child of a table element, and an input can't be a child of a table row element.表单不能是表格元素的子元素,输入不能是表格行元素的子元素。

Only table cells can be children of a table row.只有表格单元格可以是表格行的子项。

Additionally, you can't use (LEFT DOUBLE QUOTATION MARK) to delimit attribute values.此外,您不能使用 (左双引号)来分隔属性值。 Only " (QUOTATION MARK) or ' (APOSTROPHE ).只有" (引号)或' (撇号)。

Use a validator .使用验证器


Aside: Once you solve that problem you will discover that Scripting.FileSystemObject is not made available to web browsers.旁白:一旦你解决了这个问题,你会发现Scripting.FileSystemObject不能用于 Web 浏览器。 You can't write to arbitrary files with browser-side JS.您不能使用浏览器端 JS 写入任意文件。

Your doublequotes are wrong.你的双引号是错误的。

This is how it is:这是它的样子:

<input type=“submit” value=“Submit”>

This is how it needs to be:这是它需要的样子:

<input type="submit" value="Submit">

Because of that doublequotes, type is not recognised and by default input type is text.由于双引号,类型无法识别,默认情况下输入类型为文本。 Thats why you are having that problem.这就是为什么你有这个问题。

You had multiple problems.你有多个问题。

  • First the use the correct quotes helps a lot of issues.首先,使用正确的引号有助于解决很多问题。
  • Place your submit button in a td element so it won't be placed directly into a row.将提交按钮放在 td 元素中,这样它就不会直接放在一行中。
  • You used class as a variable name in your javascript which is not allowed.您在 javascript 中使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM