gpt4 book ai didi

javascript - 如何使图像可聚焦?

转载 作者:行者123 更新时间:2023-11-30 10:35:26 25 4
gpt4 key购买 nike

在另一个question ,有人建议图像可以聚焦?如何实现这一目标?

更多信息:

在另一个问题中,昆汀说:

 var img= $("#my-image-id");
image.click(function() {
// your code here
}

Don't do this. The image will not be focusable (since images are not designed to be interactive controls). People using (for instance) a keyboard to navigate through the page (instead of a pointing device like a mouse) won't be able to navigate to the image and activate the control.

还有人说:

In your case that you want to maintain the "focus" (i assume with tabbing support), if you use a single as a button (with or without ), you will have to add some JS code to make the image focusable when the appropriate tab is pressed. So you will have to write a bit more code to do the same thing.

最佳答案

要使图像(或任何元素)可聚焦,只需添加 tabindex 属性即可。

<img src="myimage.png" tabindex="1" />

但请注意,无需任何特殊处理即可使图像响应click 事件。

关于javascript - 如何使图像可聚焦?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14274257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com