backbone.js事件未绑定到文本区域上的fire操作

backbone.js events not bind to fire action on text area

本文关键字:区域 fire 操作 文本 js 事件 绑定 backbone      更新时间:2023-09-26

我的模板中有一个文本区域。我想将文本区域中的文本值传递给函数(视图)更改事件。我将"更改"事件绑定到textarea,但操作不起作用。

模板

<div id="replyt" class="commentArea">                                           <textarea id="rep" class="form-control" placeholder="What's on your mind ?" rows="2"></textarea>
    </div>

我的视图

var PostwallView = Backbone.View.extend({
 el: $("#content"),
     events: {
      'change #rep': 'test',// or which event i need
             },

我的行动

 test:function(e)
      {
      var val = $(e.currentTarget).val();
       alert( val );
    e.preventDefault();
     },

这里我使用了keyupkeydown。我的事件正在工作,但当我在文本区域中键入时,操作在第一个字符中启动

inputkeydown/up事件在值更改或按键时触发。我不知道你预计change什么时候会触发,但当文本区域失去焦点时,blur会触发:

'blur #rep': 'test'
"blur #rep":"yourMethod"

 yourMethod:function(){
 if($('#textArea').val() != null || '#textArea').val() != undefined){
  /*Call your other function here*/
}
}