繁体   English   中英

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

[英]"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">

由于双引号,类型无法识别,默认情况下输入类型为文本。 这就是为什么你有这个问题。

你有多个问题。

  • 首先,使用正确的引号有助于解决很多问题。
  • 将提交按钮放在 td 元素中,这样它就不会直接放在一行中。
  • 您在 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