getElementById,但对于每个组件而言是独一无二的
我有可重复使用的组件,需要在上面访问其“ ID”以进行滚动:
var slider = document.getElementById('slider');
slider.scrollLeft = slider.scrollLeft - (3);
ID被声明:
<div
id='slider'
className="scroll-smooth"
>
我知道这是错误的,并且只要使用多个这样的组件,它显然会失败,因为只有第一个组件的滑块交互才发生。 如何创建一个“唯一” ID(或其他)以使ID真正独特的ID?
I have reusable component on which I need to access its 'id' for scrolling:
var slider = document.getElementById('slider');
slider.scrollLeft = slider.scrollLeft - (3);
The Id is declared:
<div
id='slider'
className="scroll-smooth"
>
I know this is wrong and it obviously fails whenever more than one such component is used, as only the the first component's slider interaction takes place.
How can I create a 'unique' Id (or something else) to make the id's truly unique to each object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
useref ,而不是
getelementbyid
useRef, instead of
getElementById