亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我們可以在點擊時刪除 HTML 元素的邊框嗎?但保持邊界焦點

我們可以在點擊時刪除 HTML 元素的邊框嗎?但保持邊界焦點

浮云間 2023-09-04 16:22:45
我正在開發一個項目,考慮到網絡可訪問性。代碼:function removeBorder(){li=document.getElementById("link");li.classList.add(".remove")}body{  background:#dddddd;}p:focus{  border:1px solid red;}li{  list-style-type:none;  font-size:1rem  padding:30px;}a{text-decoration:none;}a:focus{  border:1px solid red;  border-radius:2px;}a:hover{  background:orange;}.remove{border:none;}<html>  <head>Borders  </head>  <body>  <p tabindex="0">  Click one the page. Then use TAB to navigate the list items</p><ul aria-role="list">  <li  aria-role="listitem"><a id="link" onclick="removeBorder()" tabindex="0" href="#">Item One</a></li> <li  aria-role="listitem"><a tabindex="0" onclick="removeBorder()" href="#">Item Two</a></li>  <li aria-role="listitem"><a tabindex="0"  onclick="removeBorder()"  href="#">Item Three</a></li> </ul>      </body> </html>我有兩組用戶。1.普通用戶當我將鼠標懸停在元素上時,在本例中為“li”,我看到橙色的背景色。問題:當我單擊該元素時,出現紅色邊框。有沒有一種方法可以讓我們僅在使用選項卡聚焦時才具有邊框,而在單擊時則不具有邊框?單擊時如何刪除邊框?2.僅鍵盤用戶當我們用選項卡聚焦時沒問題,邊框按預期顯示紅色。
查看完整描述

1 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

function removeBorder(){

li=document.getElementById("link");

li.classList.add(".remove")

}

body{

  background:#dddddd;

}

p:focus{

  border:1px solid red;

}

li{

  list-style-type:none;

  font-size:1rem

  padding:30px;

}

a{

text-decoration:none;

}

a:focus:hover{

  border:1px solid red;

  border-radius:2px;

}


a:hover{

  background:orange;

}

.remove{

border:none;

}

<html>

  <head>Borders

  </head>

  <body>

  <p tabindex="0">

  Click one the page. Then use TAB to navigate the list items</p>

<ul aria-role="list">

  <li  aria-role="listitem"><a id="link" onclick="removeBorder()" tabindex="0" href="#">Item One</a></li>

 <li  aria-role="listitem"><a tabindex="0" onclick="removeBorder()" href="#">Item Two</a></li>

  <li aria-role="listitem"><a tabindex="0"  onclick="removeBorder()"  href="#">Item Three</a></li>

 </ul>  

  

  </body>

 

</html>

您應該同時添加焦點和懸停,它可以工作。



查看完整回答
反對 回復 2023-09-04
  • 1 回答
  • 0 關注
  • 118 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號