将一个元素的位置绑定到另一个元素的位置

发布于 2024-10-26 15:18:51 字数 313 浏览 8 评论 0原文

jQuery 有没有办法让一个元素与另一个元素保持在同一位置?

假设有一个文本框和一个 。如何让 始终与文本框重叠,即将其绑定在同一位置?另外,当文本框因任何原因移动时,我希望 也跟着移动。

我正在考虑一个 setInterval ,它每秒检查一定次数并适当地移动 ,但是在我看来,这既昂贵又肮脏的把戏。

感谢您的任何提示。

Is there any way in jQuery to make an element stay at the same position as another element?

Say there is a textbox and a <span>. How would one let the <span> always overlap the textbox, i.e. have it bound at the same position? Also, when the textbox is moving for any reason, I'd like to have the <span> go along.

I was thinking of a setInterval which checks a certain number of times a second and move the <span> appropriately, however this is both expensive and a dirty trick in my opinion.

Thanks for any tips.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

私野 2024-11-02 15:18:51

除非我误解了您的问题,否则您可以将 放在同一个父容器中,例如a

,然后移动

而不是

Unless I am misunderstanding your question, you could put the <span> and the <input type="text" /> in the same parent container, such as a <div>, then move the <div> instead of the <input type="text" />.

鲜血染红嫁衣 2024-11-02 15:18:51

如果控制文本框移动的次数,还可以触发跨度的移动。如果没有,那么我不知道有什么事件比你的 setInterval 想法更有效。

If you control the times when the textbox moves, you can also trigger the movement of the span. If not, then I'm unaware of any events that would work better than your setInterval idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文