html 链接 id属性_HTML id属性
html 鏈接 id屬性
The id attribute is used to specify a unique id for an element in HTML. This id cannot be used for multiple elements in HTML. You can add the id to any HTML element.
id屬性用于為HTML中的元素指定唯一的ID 。 該ID不能用于HTML中的多個元素。 您可以將id添加到任何HTML元素。
The naming id attributes The id name is case-sensitive, the name must have one character and no whitespaces in two words (spaces, tabs, etc).
命名id屬性id名稱區分大小寫,名稱必須有一個字符,并且兩個單詞(空格,制表符等)中不能有空格。
使用id屬性 (Using id attribute)
The id attribute can be used to reference the HTML tag in CSS and JavaScript to perform a certain transformation in an HTML tag that contains the id attribute. We use # followed by the name of the id attribute to refer to the element.
id屬性可用于引用CSS和JavaScript中HTML標簽,以在包含id屬性HTML標簽中執行某些轉換。 我們使用#后跟id屬性的名稱來引用該元素。
在CSS中引用id屬性 (Referencing id Attribute in CSS)
<!DOCTYPE html><html><head><style>#element {background-color: #f40;color: #fff;padding: 40px;text-align: center;}</style> </head><body><h1 id="element">Hello! This is an HTML element. </h1></body></html>Output
輸出量
在JavaScript中引用id屬性 (Referencing id attribute in JavaScript)
In JavaScript also, we can use the id attribute to reference an element and perform a specific task on it. document.getElementById() is used to reference an element using JavaScript.
同樣在JavaScript中,我們可以使用id屬性來引用元素并對其執行特定任務。 document.getElementById()用于使用JavaScript引用元素。
<!DOCTYPE html><html><body><h1 id="greeting">Welcome Text</h1><button onclick="displayResult()">Say Hello!</button><script>function displayResult() {document.getElementById("greeting").innerHTML = "Hello! ";}</script></body></html>Output
輸出量
After clicking on the "Say Hello!" button...
點擊“說聲你好!”之后 按鈕...
網頁中ID的使用 (Uses of id in Webpage)
ids of elements along with links are a great way for navigation to element on the same page which is so long.
元素的id和鏈接是導航到同一頁面上太長元素的一種好方法。
Using the link to a specific id in the page will navigate us to that element in HTML.
使用指向頁面中特定ID的鏈接,可以將我們導航到HTML中的該元素。
We will see a separate example to do this.
我們將看到一個單獨的示例來執行此操作。
HTML中的類與ID屬性 (Classes vs ID Attribute in HTML)
In HTML, two elements are used to reference the HTML element. A class can be used to reference multiple HTML elements whereas id can be used to reference single HTML elements.
在HTML中,兩個元素用于引用HTML元素。 一個類可以用來引用多個HTML元素,而id可以用來引用單個HTML元素。
Read: Class attribute in HTML
閱讀: HTML中的Class屬性
翻譯自: https://www.includehelp.com/html/the-id-attribute.aspx
html 鏈接 id屬性
總結
以上是生活随笔為你收集整理的html 链接 id属性_HTML id属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【视频版】最新版Swagger 3升级指
- 下一篇: 在Java中从字符串转换为双精度