// 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(); };
}
}
}
回答
不建议模糊。如果您所看到的只是隐藏焦点线,请使用此代替:
a[i].onfocus = function() { this.hideFocus = true; };
这将适用于所有版本的IE。对于其他浏览器(包括IE8在标准模式),可以设置outline
CSS样式隐藏焦点概述:
a {
outline: none;
}
这将使您的网页更比键盘,因为它需要集中模糊的元素友好。
我建议只使用CSS去除边框。
img, a:active{
outline: none;
}
还是有一个特定的原因,为什么必须使用JS?
单独的CSS无法在IE6和IE7中执行此操作。另外,':focus'比':active'更合适,因为轮廓用于标记当前聚焦的元素。 – 2010-03-15 11:51:31
但是他不希望只在点击时才移除它吗? 使用:active将仍然允许用户查看所关注的内容,这对于非鼠标用户更友好。 – 2010-03-15 11:53:57
他的问题是关于在onfocus事件中使用'blur()',所以看起来他试图阻止他们在焦点上,而不是鼠标点击。取消轮廓的一点是您可以将自定义样式应用于':focus'。 – 2010-03-15 11:57:11
谢谢你们 - 我已经为CSS(a:focus
):
img, a:focus{
outline: none;
}
这似乎是正确的工作(黏合还在工作,当点击边框都不见了)我...在这两个即和Firefox。将不得不现在翻新一些其他链接使用它...
再次感谢。
- 1. 禁用onfocus =“this.blur();”
- 2. 输入onfocus问题
- 3. HTML的onfocus浏览器的问题
- 4. 的onfocus的onblur问题的JavaScript
- 5. 问题铬形式的处理:输入的onfocus =“this.select()”
- 6. 有关onchange/onfocus的跨浏览器问题
- 7. GWT:在Chrome中的“onFocus事件”上使用TextBox.selectAll()的问题
- 8. jQuery parent('tr')onFocus
- 9. onfocus和jquery - 困境
- 10. onFocus和onBlur
- 11. Javascript onfocus事件
- 12. HTML输入onfocus&onblur?
- 13. Dijit TabContainer事件 - onFocus
- 14. 发光按钮onfocus
- 15. 更改父类onfocus
- 16. 的onfocus用的onmouseout
- 17. onFocus方法为textField
- 18. onblur onfocus的回声形式
- 19. 链接上的onfocus事件
- 20. AngularJS [预输入]上的onfocus
- 21. JavaBeans问题表
- 22. React - inline onfocus占位符=''
- 23. 黑莓DateField onfocus颜色
- 24. 停止输入清除onFocus
- 25. 的onfocus气泡在阵营
- 26. IE7文本框的onfocus
- 27. React中的'onFocus'的对面
- 28. 突出字段内容onFocus
- 29. ImageButton颜色不变onPressed(),onFocus()
- 30. 如何使用jQuery显示标题属性onfocus?
不要这样做!它使得使用非指向设备导航页面成为不可能。您将使人们无法使用键盘,取决于呼吸开关等。 – Quentin 2010-03-15 11:47:00