2014-04-25 28 views
2

我在我的模板中有一個文本區域。我想從文本區域傳遞文本值到函數(視圖)更改事件。我將「更改」事件綁定到textarea,但操作不起作用。backbone.js事件不綁定到文本區域的火動作

模板

<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(); 

    }, 

在這裏,我用keyup和​​。當我在文本區域中輸入時,我的事件正在工作但在第一個字符中發生了動作

回答

1

當值更改或按下某個鍵時,會觸發inputkeydown/up事件。我不知道,當你想到change觸發,但blur當文本區域失去焦點觸發:

'blur #rep': 'test' 
+1

但是當我點擊空文本框的行動是火 – square

+0

在任何地方我標籤頁的消防行動@jgillich – Sport

+0

我想讀取textarea的值 – Sport

0
"blur #rep":"yourMethod" 


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