小编xon*_*n1c的帖子

是否可以在不使用setTimeout()函数的情况下获取粘贴文本?

我发现当Hello使用鼠标粘贴文本(即)时,以下函数将抛出一个空的弹出窗口:

$('input:text').onpaste = function()
{
    alert($('input:text').val());
});
Run Code Online (Sandbox Code Playgroud)

问题是,当onpaste事件被触发时,文本实际上还没有粘贴到输入字段(至少这是我的猜测).所以将功能更改为:

$('input:text').onpaste = function()
{
    setTimeout(function()
    {
        alert($('input:text').val()
    }, 100);
}
Run Code Online (Sandbox Code Playgroud)

通过Hello在粘贴到输入字段时显示带有文本的弹出窗口来提供正确的结果.

现在我的问题是:是否有可能在不使用该setTimeout()功能的情况下捕获粘贴的文本?这种解决方法看起来很脏,所以我很乐意不必使用它.

kkthxbai xon1c

javascript jquery events timeout paste

7
推荐指数
1
解决办法
4969
查看次数

Vector.erase(Iterator)导致错误的内存访问

我正在尝试进行videoObjects存储在a中的Z-Index重新排序vector.计划是确定videoObject哪个将被放置在第一个位置vector,擦除它然后将其插入第一个位置.不幸的是,该erase()功能总是导致错误的内存访

这是我的代码:

testApp.h:

vector<videoObject> videoObjects;
vector<videoObject>::iterator itVid;
Run Code Online (Sandbox Code Playgroud)

testApp.cpp:

// Get the videoObject which relates to the user event
for(itVid = videoObjects.begin(); itVid != videoObjects.end(); ++itVid) {
  if(videoObjects.at(itVid - videoObjects.begin()).isInside(ofPoint(tcur.getX(), tcur.getY()))) {
   videoObjects.erase(itVid);
  }
}
Run Code Online (Sandbox Code Playgroud)

这应该是如此简单,但我只是没有看到我在哪里走错了路.

c++ vector erase openframeworks

4
推荐指数
1
解决办法
7128
查看次数

标签 统计

c++ ×1

erase ×1

events ×1

javascript ×1

jquery ×1

openframeworks ×1

paste ×1

timeout ×1

vector ×1