开发者

Is this possible to select with keyboard tab a Span Object?

开发者 https://www.devze.com 2023-03-28 01:58 出处:网络
Is this possible to select with keyboard tab开发者_如何学编程 a Span Object? I have applied onclick function to that span. I want to select the span along with anchor tags with keyboard tab button.

Is this possible to select with keyboard tab开发者_如何学编程 a Span Object? I have applied onclick function to that span. I want to select the span along with anchor tags with keyboard tab button.

Thanks in advance


No. It's very bad idea to do so! Better is to dynamically add anchor element styled like a span, note that onclick should return false, to prevent browser from loading new page. Here your code


Try something like this

$(body).keyup(function(event) {
    if (event.keyCode == '9') { 
        //select the text
    }
});

As for selecting the text itself. See this answer


One way to do this is by using tabindex="0" in the span tag. Keeping tabindex="-1" skips the element when tab is used.

<span tabindex="0">Focus this element on tab</span>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号