te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Ctrl+V ( Paste ) triggers jQuery's keyup function TWICE - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ctrl+V ( Paste ) triggers jQuery's keyup function TWICE - Stack Overflow

programmeradmin4浏览0评论

How to make Ctrl+V or Paste not trigger the keyup function TWICE?

This is a problem for me because I made an AutoComplete functionality, and it displays the same data twice when i paste in a textbox. I hope this makes more sense now.

EDIT:

Okay guys, I have found out how to detect Ctrl+V by $('#this-id').bind('paste', function() {});

But now another follow up question is how to bine it with keyup so that when paste is pressed, keyup wont trigger anymore.

How to make Ctrl+V or Paste not trigger the keyup function TWICE?

This is a problem for me because I made an AutoComplete functionality, and it displays the same data twice when i paste in a textbox. I hope this makes more sense now.

EDIT:

Okay guys, I have found out how to detect Ctrl+V by $('#this-id').bind('paste', function() {});

But now another follow up question is how to bine it with keyup so that when paste is pressed, keyup wont trigger anymore.

Share Improve this question edited Sep 16, 2017 at 16:54 Fabrizio 8,0436 gold badges56 silver badges115 bronze badges asked Apr 1, 2014 at 6:56 user2881063user2881063 1,0591 gold badge10 silver badges19 bronze badges 5
  • 3 Why is it a problem for you? You do release two keys (V and CTRL) after all... – ThiefMaster Commented Apr 1, 2014 at 6:58
  • 2 Do you have any trials respective to the question asked? actually this question does not make any sense. – Jai Commented Apr 1, 2014 at 6:59
  • Why don't you use keydown to trap the Ctrl key and keyup to trap the V key? – CodingIntrigue Commented Apr 1, 2014 at 7:02
  • okay! i have some issues like this before in the inclusion of same script twice, you can check for that. – Jai Commented Apr 1, 2014 at 7:03
  • Then how about if 'V' is a part of the letters i am typing to search in an autoplete i made? @RGraham – user2881063 Commented Apr 1, 2014 at 7:04
Add a ment  | 

3 Answers 3

Reset to default 15

Okay guys, Thank you all for your answers but as I go through some reading, a lot of blogs say this: "IF you're implementing an autoplete functionality, DON'T rely on 'keyup' function"

So I changed my code to $('#this-id').bind('input', function() {});

And it worked, I don't have to worry now about pasting or anything else. I hope this helps to others too.

you can try this

$(window).on('keyup', function (event) {
    if (!event.ctrlKey) {
        /* here your code for all keys besides CTRL ;-) */
    }
});

You could use underscore's debounce to set delay for reading the keyup event.

See the working code at:

JSFiddle

JS:

var count = 0;
function lookup() {
    $('div#test').html($('input.text').val());
    count++;
    $('div#count').html(count);
}

$(document).keyup( _.debounce(lookup, 250, true) );

HTML:

<div>
    <input type="text">
</div>

Input: <div id="test"></div>
Keyup Count: <div id="count"></div>

underscore.js from:

http://documentcloud.github./underscore/underscore-min.js

发布评论

评论列表(0)

  1. 暂无评论