2016-11-20 71 views
0

我最近建立了一個網頁,讓我更多地瞭解HTML,而且我發現'required'屬性。我將它添加到了字段中,但它沒有做任何事情。「必要」的屬性不工作

誰能告訴我,我的「需要」屬性的錯誤?

我希望它說:「請填寫此場」時,該字段爲空

<html> 
     <head> 
      <link href="icon.ico" rel="icon"> 
      <title>Log In</title> 
     </head> 
     <body> 
      <h1 align="center">Welcome to site</h1> 
      <hr width="50%"/> 
      <br/> 
      <table align="center"> 
       <form> 
        <tr> 
         <td>Log In : </td> 
         <td><input type="text" name="LogInEmail" placeholder="Enter your email" required></td> </tr><tr> 
         <td>Password : </td> 
         <td><input type="password" name="password" placeholder="Password" required></td> 
        </tr> 
       </form> 
      </table> 
      <br/> 
       <table align="center"> 
        <form> 
        <tr> 
         <td><input type="submit" value=" Log In "/></td> 
        </tr> 
       </form> 
      </table> 
     </body> 
    </html> 
+0

您好,請提供您的期望和實際結果使社區可以幫助您與您的「錯誤」(你沒有描述)。 – Gildas

+0

我只是想,如果任何一個領域的未填充比我想消息「請填寫此場」 @Gildas –

+0

的可能的複製[HTML5必要屬性不工作(http://stackoverflow.com/questions/17791818/HTML5要求的屬性 - 不工作) – JumpingJezza

回答

0

請確保您有第一個表單裏面提交。 你有多種形式。因此要求不起作用。

<html> 
    <head> 
    <link href="icon.ico" rel="icon"> 
    <title>Log In</title> 
    </head> 
    <body> 
    <h1 align="center">Welcome to site</h1> 
    <hr width="50%" /> 
    <br/> 
    <table align="center"> 
     <form id="form1" runat="server"> 
     <tr> 
      <td>Log In : </td> 
      <td> 
      <input type="text" name="LogInEmail" placeholder="Enter your email" required> 
      </td> 
     </tr> 
     <tr> 
      <td>Password : </td> 
      <td> 
      <input type="password" name="password" placeholder="Password" required> 
      </td> 
     </tr> 
     <tr> 
      <td> 
      <input type="submit" value=" Log In " /> 
      </td> 
     </tr> 
     </form> 
    </table> 
    </body> 
</html> 

但是,如果你在有多個表和形式,前提交堅持,你可以驗證第一種形式。如果我沒有錯,你正在嘗試有一個更好的用戶界面佈局,可以處理CSS而不是多個表格和表格。

0

正如你(@蘇尼爾-B-N)回答說,「需要」屬性並不多形式標籤看到這裏是不是在單一形式標籤工作的工作。

<html> 
    <head> 
     <title>Sign Up</title> 
    </head> 
    <body> 
     <h1 align="center">Registration Form</h1><br/><br/> 
      <blockquote item-width="1010"> <fieldset> 
       <table align="center"> 

        <form type="get"> 
        <tr> 
         <td>First Name :</td> 
         <td><input type="text" placeholder="First Name" required></td> 
        </tr> 
        <tr> 
         <td>Last Name :</td> 
         <td><input type="text" placeholder="Last Name"></td> 
        </tr> 
        <tr> 
         <td>Gender</td> 
         <td><input type="radio" value="male" name="Gender">Male<br/><input type="radio" value="female" name="Gender">Female</td> 
        </tr> 
        <tr> 
         <td>Birth Date :</td> 
         <td><input type="date" ></td> 
        </tr> 
        <tr> 
         <td>Mobile :</td> 
         <td><input type="text" placeholder="Enter Mobile Number" required></td> 
        </tr> 
        <tr> 
         <td>Email :</td> 
         <td><input type="text" placeholder="Enter Email" required></td> 
        </tr> 
        <tr> 
         <td>Password :</td> 
         <td><input type="password" placeholder="Enter Password" required></td> 
        </tr> 
        <tr> 
         <td>Password :</td> 
         <td><input type="password" placeholder="Re-Enter Password" required></td> 
        </tr> 
        <tr> 
         <td><input type="reset" value="Reset"></td> 
         <td><input type="submit" value="Submit" onclick="window.location.href=('Thanks.html')"></td> 
        </tr>    
       </form> 
      </table> 
     </fieldset></blockquote> 
    </body> 
</html> 
0

你拿了兩個表單。你應該把你的提交按鈕放在同一個表單中輸入require字段exists.Be小心表單。