将链接拖动到输入并将其文本附加到其中

发布于 2024-12-28 10:03:14 字数 292 浏览 3 评论 0原文

如果将任何超链接 拖动到输入(例如搜索输入),则 href 属性将附加到输入的内容中,< input type="text" value="http://domain.com/go.php" />

有没有办法附加 title 属性,或者 innerHtml

我问这个是因为我想避免使用 jQuery UI 的可拖动扩展。

任何想法都会有所帮助。

if you dragg any hyperlink <a href="go.php"> to an imput (for example a search input), the href attribute is append to the input's content, <input type="text" value="http://domain.com/go.php" />

Is there a way to append the title attribute instead, or the innerHtml?

I ask this because I want to avoid the use of jQuery UI's draggable extension.

Any ideas will be helpful.

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

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

发布评论

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

评论(2

深海夜未眠 2025-01-04 10:03:14

如果您将任何超链接拖动到输入(例如
搜索输入),href 属性附加到输入的内容,

我认为你的意思是输入的值设置为链接的href。无论如何,它不在 IE 8 中。

还有其他拖放库,其开销比 jQuery + jQueryUI 少得多,我怀疑其中许多库将允许您在将一个元素拖动到另一个元素时执行您想要的操作。例如 myLibrary 有一个 attachdrag 函数,您可以在其中指定删除元素时发生的情况。

因此,只需检查删除的元素的标记名,如果它是 A,则查找 href 以检查它是否是链接,然后执行您想要的操作。

if you dragg any hyperlink to an imput (for example
a search input), the href attribute is append to the input's content,

I think you mean that the value of the input is set to the href of the link. Anyway, it isn't in IE 8.

There are other drag and drop libraries with much less overhead than jQuery + jQueryUI, I suspect that many of them will allow you to do what you want when one element is dragged to another. e.g. myLibrary has an attachdrag function where you can specify what happens when an element is dropped.

So just check the dropped element's tagname and if it's an A, look for the href to check if it's a link then do what you want.

伴随着你 2025-01-04 10:03:14

正如 James 所说,这确实是浏览器功能,JavaScript 似乎无法拦截它;也就是说,如果您将元素拖入输入字段,则当您在输入字段上释放鼠标时,不会触发任何事件。如果您设置不使用可拖动,一种替代方法是每当鼠标落在链接上时在输入元素上放置遮罩,存储它们的位置,然后在鼠标返回时查询这些位置以确定哪个输入字段是有针对性。

As James said, this is indeed a browser feature, and it doesn't seem that JavaScript can intercept it; that is, no event fires when you release your mouse over an input field if you're dragging an element into it. If you're set on not using draggable, one alternative would be to put masks over your input elements whenever the mouse goes down on a link, store their positions, then query those positions when the mouse goes back up to determine which input field was targeted.

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