Clear input field when data is dragged and dropped
I wrote a function that automatically clears the preset value of an input field when the user focusses on it, and puts it back on blur if the user does not input any value.
so the value of <input type="text" value="example" />
would be set to nothing on focus.
The problem I am facing is as follows:
When I select a bit of text on the page and drag and drop it into the input field, the field will not be cleared before the dropped text is applied.
Instead the value of the input field will become: exampleLorem, opposed to just Lorem.
Is there a pro开发者_如何学运维per way to remove the default value right after the text is dropped into the input field?
There are a couple of other events you can use than focus and blur
Most interesting to this issue should be drop, dragenter and dragleave
Please note: in MSIE it looks like the focus-event fires immediatly after drop, so you need a kind of flag to set on drop (and remove this flag a moment later), to handle a invocation of focus forced by drop.
Also note: unfortunately opera doesn't support those dragdrop-events
Perhaps you can clear the preset not on focus, but on hover (or mouseover)?
精彩评论