📜  HTML | DOM 链接对象

📅  最后修改于: 2021-11-07 08:22:12             🧑  作者: Mango

HTML DOM 链接对象用于访问HTML 元素

句法:

  • 访问 HTML 元素:
    document.getElementById("myLink"); 
  • 创建一个新的 HTML 元素:
    document.getElementById("myLink"); 

    属性值:

    Value Description
    charset It assigns the character encoding of the linked document
    crossOrigin It assigns the the CORS settings of the linked document
    disabled It assigns whether the linked document is disabled, or not
    href It is used to set/return the URL of the linked document
    hreflang It assigns the language code of the linked document
    media It assigns the media type for the link element
    rel It assigns the relationship between the current document and the linked document
    rev It assigns the reverse relationship from the linked document to the current document
    sizes Returns the sizes attribute’s value of the linked resource
    type It is used to set/return the content type of the linked document

    示例 1:访问链接元素。

    
    
      
    
        
    
      
    
        

    TO ACCESS LINK ELEMENT:

           

    PRESS THE BUTTON TO GET THE URL        OF THE LINKED DOCUMENT.

                   

                 

    输出:

    点击前:

    点击后:

    示例 2:创建链接元素。

    
    
      
    
    
      
    
        

    TO CREATE A LINK ELEMENT.

                

              

    输出:

    点击前:

    点击后:

    支持的浏览器:

    • 铬合金
    • 火狐
    • 互联网浏览器
    • 苹果浏览器
    • 歌剧