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

javascript - METEOR on change event only get's fired on a text area after you click out of the text area - Stack Overflo

programmeradmin2浏览0评论

Here is my template:

<template name="textGoesHere">
{{#if currentUser}}
    <div id="boxdiv">
        <textarea id="box">{{user.text}}</textarea>
    </div>

{{/if}}
</template>

Here is my Meteor event:

'change #box': function (e) {
        Meteor.call('click', $("#box").val());

}

For some reason, this event only gets fired after you click out of the text area after you've changed it's contents. But apparently, the event is suppose to be called when the text area is changed which is the functionality I'm looking for.

Here is my template:

<template name="textGoesHere">
{{#if currentUser}}
    <div id="boxdiv">
        <textarea id="box">{{user.text}}</textarea>
    </div>

{{/if}}
</template>

Here is my Meteor event:

'change #box': function (e) {
        Meteor.call('click', $("#box").val());

}

For some reason, this event only gets fired after you click out of the text area after you've changed it's contents. But apparently, the event is suppose to be called when the text area is changed which is the functionality I'm looking for.

Share Improve this question asked Dec 28, 2014 at 1:45 Tyler James LeonhardtTyler James Leonhardt 8841 gold badge10 silver badges24 bronze badges 3
  • 1 Um, that is how JavaScript's onchange works in general. The event does not fire until the user leaves the element. If you want something different, you will need to use keypress/input and timers. – epascarello Commented Dec 28, 2014 at 1:46
  • Unfortunately, I'm looking to solve a case where a user would paste something into the text area. keypress, timers, and change events don't fire instantaneously after some one pastes. – Tyler James Leonhardt Commented Dec 28, 2014 at 3:02
  • 1 So listen for input/paste event. – epascarello Commented Dec 28, 2014 at 3:21
Add a ment  | 

2 Answers 2

Reset to default 5

Try looking for the following events if you want to cover your bases for handling that kind of input: 'input change paste keyup mouseup'

A little more prehensive (for me) with this :

'change #box, paste #box, keyup #box, mouseup #box': function (e) {
        Meteor.call('click', $("#box").val());

}
发布评论

评论列表(0)

  1. 暂无评论