MRA*_*MRA 4 html javascript jquery
通常,当将标记的文本拖放到HTML输入元素中时,标记的文本将复制到该输入字段中的光标位置(并添加到任何现有文本).我想使用jQuery改变这种行为,使其类似于(例如)Firefox地址字段的行为,即:
有谁知道实现这一目标的方法?任何帮助表示赞赏.
在我看来,为此,我需要识别某种"拖放"事件并访问拖动的文本,虽然我不知道这是否可能.我想到的场景的(非功能性)模型如下所示:
HTML:
<p>drag-and-drop text into this:</p>
<input id="giveittome" value="some text"></input>
<p>other text</p>
<p>more text</p>
<p>whatever</p>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
$('#giveittome').on('drag-and-drop' , function (event) {
$(this).val(event.getDraggedText());
});
Run Code Online (Sandbox Code Playgroud)
试试这个:(它适用于大多数现代浏览器)
$('input').on('keydown change paste drop',function(event) {
var _this = this;
setTimeout(function() {
console.log(_this.value, event.type);
}, 0); //this timeout is necessary to get the value
});
Run Code Online (Sandbox Code Playgroud)
小提琴:http://jsfiddle.net/maniator/7skY7/
| 归档时间: |
|
| 查看次数: |
226 次 |
| 最近记录: |