您好,登錄后才能下訂單哦!
這篇文章主要介紹了Bootstrap中aria-label和aria-labelledby屬性有什么用,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
aria-label
正常情況下,form表單的input組件都有對應的label.當input組件獲取到焦點時,屏幕閱讀器會讀出相應的label里的文本。
<!DOCTYPE html> <html> <head> <meta charset = "utf-8"> <title>demo</title> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="external nofollow" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdn.bootcss.com/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh5U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> <style type="text/css"> body{padding: 20px;} </style> </head> <body> <form role = "form"> <div class="form-group col-lg-3 form-horizontal"> <label for = "idCard" class="control-label col-lg-5">身份證號:</label> <div class="col-lg-7"> <input type = "text" id = "idCard" class="form-control"> </div> </div> </form> </body> </html>
但是如果我們沒有給輸入框設置label時,當其獲得焦點時,屏幕閱讀器會讀出aria-label屬性的值,aria-label不會在視覺上呈現效果。
<body> <form role = "form"> <div class="form-group col-lg-3 form-horizontal"> <div class="col-lg-7"> <input type = "text" id = "idCard" class="form-control" aria-label = "身份證號"> </div> </div> </form> </body> aria-labelledby <body> <div class="dropdown"> <button type="button" class="btn dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown"> 選擇您的職位 <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1"> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >測試工程師</a> </li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >開發工程師</a> </li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >銷售工程師</a> </li> </ul> </div> </body>
注:
如果一個元素同時有aria-labelledby和aria-label,讀屏軟件會優先讀出aria-labelledby的內容
感謝你能夠認真閱讀完這篇文章,希望小編分享的“Bootstrap中aria-label和aria-labelledby屬性有什么用”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。