【问题标题】:HTML code- the output is not what i wantHTML 代码 - 输出不是我想要的
【发布时间】:2018-01-21 21:26:19
【问题描述】:
 <body>
  <form action= "http://norton.open.ac.uk/reflect.php" method= "post" name= "form1">
      <h1> Book Details: </h1>
     <select name= "dropdown">
        <option value= "Books" selected>Books</option>
        <option value= "Magazines">Magazines</option>
        <option value= "Journals">Journals</option>
        <option value= "Newspapers">Newspapers</option>

     <p>
     <b>Book name:</b>  <input type = "text" name = "book_name" /> </p>
     <p>
     <b>Author:</b>  <input type = "text" name = "author" /> </p>
     <p>
     <b>Publication Year:</b>  <input type = "date" name = "publication_year" /> </p>
     <p>
     <b>ISBN Number:</b>  <input type = "number" name = "isbn_number" /> </p>

     <input type= "submit" name= "submit" value= "Submit" />
   </form>

我很确定代码有问题,但我无法确定它到底是什么。输出不是我想要的。

【问题讨论】:

  • 您的预期输出是什么?
  • “输出不是我想要的。” - 你想要什么输出
  • 不要将表单控件命名为“提交”,或者任何其他与标准表单属性匹配的名称,因为它会掩盖该属性。没有javascript时为什么要javascript标签?
  • The output is not what I want.it doesn't work 就问题描述而言
  • @NickCoad——不,但是有一个名为 submit 的标准 form 属性(它是 submit 方法)并且它确实覆盖了表单的 submit 属性,因为命名控件是按命名添加的表格的属性。试试&lt;form&gt;&lt;input type="button" name="submit" onclick="this.form.submit()" value="Submit form"&gt;&lt;/form&gt;。它将失败,因为this.form.submit 指的是按钮,而不是方法。将按钮名称更改为其他任何名称(或将其删除)并且它可以工作。 ;-)

标签: javascript html css


【解决方案1】:

因此,您需要做几件事才能使其正常工作...

<input type="submit" />

如果您需要在 JS 中设置某种提交,则可以使用 id。

不确定 100% 你在这里做什么,但你的表单可能看起来像这样:

<form action="http://norton.open.ac.uk/reflect.php" id="form1">
    <div>
        <label for="book">Book Name:</label>
        <input type="text">
    </div>
    <div>
        <label for="author">Author:</label>
        <input type="text">
    </div>
    <div>
        <label for="publication">Publication Year:</label>
        <input type="text">
    </div>
    <div>
        <label for="isbn">ISBN Number:</label>
        <input type="number">
    </div>
    <div>
        <input type="submit">
    </div>
</form>

确保您在 HTML 元素标签中的值是:type="" 与您当前状态下的值 type= ""。中间不需要空格。

此外,为了将来的参考,请多说明您要完成的工作。如果您正在提交这样的表单并且您正在使用 JS,请指定当前输出是什么以及您想要的输出是什么。如果您提供了一些您为解决问题所做的研究,这也会有所帮助。

希望对你有所帮助!

【讨论】:

    猜你喜欢
    • 2015-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 2019-12-18
    相关资源
    最近更新 更多