将链接拖动到输入并将其文本附加到其中
如果将任何超链接 拖动到输入(例如搜索输入),则 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的意思是输入的值设置为链接的href。无论如何,它不在 IE 8 中。
还有其他拖放库,其开销比 jQuery + jQueryUI 少得多,我怀疑其中许多库将允许您在将一个元素拖动到另一个元素时执行您想要的操作。例如 myLibrary 有一个 attachdrag 函数,您可以在其中指定删除元素时发生的情况。
因此,只需检查删除的元素的标记名,如果它是 A,则查找 href 以检查它是否是链接,然后执行您想要的操作。
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.
正如 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.