weixin_33709609 2011-11-13 01:09 采纳率: 0%
浏览 23

拖放到文本框中

I have a list of people on the left hand side of a page, this list is populated by PHP.

Each person is in their own div (this can be changed but I thought div's may be easier to work with). I want to be able to drag any one of these people onto a textbox, thus entering their name into that textbox.

Also to make it more awkward, I don't really want to be using jQuery or prototype. Or any of the others really.

Edit:
Sorry let me rephrase the question...
How would I check to see if something has been dragged on top of a textbox? And how would I get the ID of that element?

What I don't know is how to check if something has been dragged on top of the textbox (input box, not text area, but that's no big issue.)
I know there would never be a magical param like onDragOnto="" but hopefully that will show you what I mean

  • 写回答

1条回答 默认 最新

  • local-host 2011-11-13 01:13
    关注

    Without more details, I can't really provide a better answer.

    How about clicking within the DIV element resulting in a Javascript event to be fired which causes the element's text to be selected? Then, you can drag this text into a multiline textarea.

    Now, with the information from the edit:

    You'd register a onmousedown event with each DIV that you have.

    On the names:

    <div onmousedown="onMouseDown(event);" onmouseup="onMouseUp(event);">Jane</div>
    

    On the textarea/textbox:

    <textarea onmouseover="return onMouseOver(event);"></textarea>
    

    And a script:

    <script>
    
    function onMouseOver(evt) {
        target = document.lastClicked;
        if (target != null) {
            window.alert(target.id);
        }
    }
    
    function onMouseDown(evt) {
        document.lastClicked = window.event.target;
    }
    
    function onMouseUp(evt) {
        document.lastClicked = null;
    }
    
    </script>
    

    This is a very crude way to do things, but I hope this gives you the principles that you're looking for. If you want to force the elements to move rather than just using text drag-and-drop, then things get more hairy. To handle that, you'll need to use CSS and modify the coordinates.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器