當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


HTML dirname屬性用法及代碼示例

HTML | dirname屬性用於在提交表單後啟用輸入的文本方向和Textarea字段。 dirname屬性的值必須是輸入字段和textarea的名稱,後跟“.dir”。它可以與<input>和<textarea>元素一起使用。

  • <input>元素中的Dirname屬性:
    用法:
    <input name="myname" dirname="myname.dir">

    示例1:本示例說明了輸入元素中dirname屬性的用法。

    <!DOCTYPE html> 
    <html> 
      
    <head> 
        <style> 
            h1 { 
                color:green; 
            } 
        </style> 
    </head> 
      
    <body> 
      
        <form action="/action_page.php"> 
            <h1> 
              GeeksforGeeks 
          </h1> 
            <h2> 
              HTML | dirname attribute 
          </h2> First name:
            <input type="text" name="fname" dirname="fname.dir"> 
      
            <input type="submit" value="Submit"> 
        </form> 
      
        <p> 
          After the Submission of the form,  
          the text direction of the input  
          field will also be submitted. 
        </p> 
      
    </body> 
      
    </html>

    輸出:

  • <textarea>元素中的dirname屬性:
    用法:
    <textarea name="myname" dirname="myname.dir"></textarea>

    示例-2:本示例說明了Textarea元素中dirname屬性的使用。

    <!DOCTYPE html> 
    <html> 
      
    <head> 
        <style> 
            h1 { 
                color:green; 
            } 
        </style> 
    </head> 
      
    <body> 
      
        <form action="/action_page.php"> 
            <h1> 
              GeeksforGeeks 
          </h1> 
            <h2>HTML | dirname attribute 
          </h2> 
            <textarea name="Geeks" dirname="geeks.dir" 
                      placeholder="write something here"> 
            </textarea> 
            <input type="submit" value="Submit"> 
        </form> 
      
        <p> 
            After the Submission of the form, the text  
            direction of the Textarea field will also,  
            be submitted. 
        </p> 
    </body> 
      
    </html>

    輸出:

支持的瀏覽器:dirname屬性支持的瀏覽器如下:

  • 穀歌瀏覽器
  • Opera
  • Safari




相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | dirname Attribute。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。