// 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(); };
}
}
}
答案 0 :(得分:3)
谢谢你们 - 我已经去了css(a:focus
):
img, a:focus{
outline: none;
}
对于我来说,似乎工作正常(标签仍在工作,点击时边框消失了)...在ie和firefox中。现在必须改进一些其他链接才能使用它......
再次感谢。
答案 1 :(得分:2)
不建议模糊。如果你正在做的就是隐藏焦点线,请改用:
a[i].onfocus = function () { this.hideFocus = true; };
这适用于所有版本的IE。对于其他浏览器(包括标准模式下的IE8),您可以设置outline
CSS样式以隐藏焦点轮廓:
a {
outline: none;
}
这会使您的页面比模糊元素更加键盘友好,因为它需要关注。
答案 2 :(得分:1)
我建议只使用CSS删除边框。
img, a:active{
outline: none;
}
或者是否有必须使用JS的特定原因?