首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >onfocus="this.blur();“问题

onfocus="this.blur();“问题
EN

Stack Overflow用户
提问于 2010-03-15 19:41:14
回答 3查看 8.9K关注 0票数 3
代码语言:javascript
复制
// I am trying to apply an "onfocus="this.blur();"" so as to remove the dotted border lines around pics that are being clicked-on
  // the effect should be applied to all thumb-nail links/a-tags within a div..

  // sudo code (where I am):
  $(".box a").focus(  // so as to effect only a tags within divs of class=box |  mousedown vs. onfocus vs. *** ?? | javascript/jquery... ???
  function () 
  {
      var num = $(this).attr('id').replace('link_no', ''); 
      alert("Link no. " + num + " was clicked on, but I would like an  onfocus=\"this.blur();\" effect to work here instead of the alert...");

      // sudo bits of code that I'm after:
      // $('#link_no' + num).blur();
      // $(this).blur();
      // $(this).onfocus = function () { this.blur(); };


  }
  );

 // the below works for me in firefox and ie also, but I would like it to effect only a tags within my div with class="box"
   function blurAnchors2() 
             {
              if (document.getElementsByTagName) {
                   var a = document.getElementsByTagName("a"); 
                    for (var i = 0; i < a.length; i++) {
                          a[i].onfocus = function () { this.blur(); };
              }
                }
          }
EN

回答 3

Stack Overflow用户

发布于 2010-03-15 20:46:09

谢谢你们--我已经找到了css(a:focus):

代码语言:javascript
复制
img, a:focus{
    outline: none;
}

对我来说,它似乎工作正常( the键仍然有效,点击时边框消失了)。在ie和火狐中都有。现在必须翻新一些其他链接才能使用它。

再次感谢。

票数 3
EN

Stack Overflow用户

发布于 2010-03-15 19:44:28

不建议进行模糊处理。如果你想做的就是隐藏焦点线,那就用下面的代码:

代码语言:javascript
复制
a[i].onfocus = function () { this.hideFocus = true; };

这将适用于所有版本的IE。对于其他浏览器(包括标准模式下的IE8 ),您可以设置outline CSS样式以隐藏焦点轮廓:

代码语言:javascript
复制
a {
    outline: none;
}

这将使您的页面比在获取焦点时模糊元素的键盘友好得多。

票数 2
EN

Stack Overflow用户

发布于 2010-03-15 19:49:09

我建议只使用CSS来删除边框。

代码语言:javascript
复制
img, a:active{
    outline: none;
}

或者一定要使用JS有什么特别的原因?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2446769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档