In Firefox only, if I highlight text and drop it into the middle of an existing textfield I get an error message:
仅在Firefox中,如果我突出显示文本并将其放到现有文本字段的中间,我会收到一条错误消息:
The URL is invalid and cannot be loaded.
该URL无效,无法加载。
I created a sample here http://jsfiddle.net/XtGdd/2/
我在这里创建了一个示例http://jsfiddle.net/XtGdd/2/
Highlight the drag me
text. Then click and drag it into the text of the input box. - If I drop it after the input text, it will run fine. - If I drop it inside the input text I get the error.
突出显示拖动文本。然后单击并将其拖动到输入框的文本中。 - 如果我在输入文本后删除它,它将运行正常。 - 如果我将其放入输入文本中,我会收到错误。
Does anyone know why this is happening and how to work around it?
有谁知道为什么会这样,以及如何解决它?
What I am trying to do is to replace the value of the textfield by the one dropped. In this case, to clear the field and replace with the dropped text.
我想要做的是用删除的文本字段替换文本字段的值。在这种情况下,要清除字段并替换为删除的文本。
1 个解决方案
#1
2
I have found a solution I put in http://jsfiddle.net/XtGdd/12/ thanks from this question
我在http://jsfiddle.net/XtGdd/12/找到了一个解决方案,感谢这个问题
$('#text_input_')
.bind("dragover", false) #=> for Chrome to catch the drop event;
.bind("dragenter", false) #=> for Chrome to catch the drop event;
.bind('drop', function(e){ #=> Cancel the drop and just set the value directly;
$('#text_input_').val(e.originalEvent.dataTransfer.getData("text/plain"));
return false;
});
I don't really feel safe with it but at the moment, that is the only thing I found.
我真的觉得不安全,但此刻,这是我发现的唯一一件事。
#1
2
I have found a solution I put in http://jsfiddle.net/XtGdd/12/ thanks from this question
我在http://jsfiddle.net/XtGdd/12/找到了一个解决方案,感谢这个问题
$('#text_input_')
.bind("dragover", false) #=> for Chrome to catch the drop event;
.bind("dragenter", false) #=> for Chrome to catch the drop event;
.bind('drop', function(e){ #=> Cancel the drop and just set the value directly;
$('#text_input_').val(e.originalEvent.dataTransfer.getData("text/plain"));
return false;
});
I don't really feel safe with it but at the moment, that is the only thing I found.
我真的觉得不安全,但此刻,这是我发现的唯一一件事。