最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

detecting change in a text input box using jqueryjavascript - Stack Overflow

programmeradmin3浏览0评论

in html and javascript, I can use keyup, focus, blur to detect most of the content changes in a text input, however if the user do a copy and paste into the text input, how do I capture this change? The issue here is that the input is already in focus when user paste into it.

in html and javascript, I can use keyup, focus, blur to detect most of the content changes in a text input, however if the user do a copy and paste into the text input, how do I capture this change? The issue here is that the input is already in focus when user paste into it.

Share Improve this question asked Jul 2, 2009 at 2:35 user121196user121196 31k60 gold badges149 silver badges202 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

You could capture the paste event (http://www.quirksmode/dom/events/cutcopypaste.html)

$("#myinput").bind("paste",function(){
    //code here
})
$("#myinput").change(function(){
    // whatever you need to be done on change of the input field
});

// Trigger change if the user type or paste the text in the field
$("#myinput").keyup(function(){
    $(this).change();
});

// if you're using a virtual keyboard, you can do :
$(".key").live('click',function(){
    $("#myinput").val($("#myinput").val()+$(this).val());
    $("#myinput").change(); // Trigger change when the value changes
});

the textbox has an OnChange event that fires when a) the text box loses focus AND the value within the text box has changed.

发布评论

评论列表(0)

  1. 暂无评论