2012-07-11 33 views
0

我用敲除和得到了我的模型视图模板这些回来......不能得到文本区域的价值

<div class="both"> 
    <td> 
    <h3 data-bind="text: MyText"> What type of fruit is healthy ?</h3> 
    <textarea data-bind="attr:{id: Question}" class="my-response" id="1"> this is my text area value </textarea> 
    </td> 
</div> 

<div class="both"> 
    <td> 
     <h3 data-bind="text: MyText"> What type of Veg is healthy ?</h3> 
     <textarea data-bind="attr:{id: Question}" class="my-response" id="2"> this is my text area value</textarea> 
    </td> 
</div> 

我想要得到文本区域的价值,这是行不通的..

$('.both').each(function() { 
alert($('.my-response').val()); 
}); 

我该怎么做?

感谢

+0

你肯定对HTML格式? – 2012-07-11 19:47:08

+4

尽管使用它来绑定,但您似乎没有充分利用淘汰赛获取您的模型信息。你确定你需要用jQuery收集这些信息吗? – Tyrsius 2012-07-11 21:57:40

+0

绑定你的textareas的值:绑定,你/不需要jQuery来访问值! – thomaux 2012-07-12 08:20:40

回答

2

试试这个

$(function(){ 

    $('.both').each(function(index,item) { 
     var v= $(item).find('.my-response').val(); 
     alert(v); 
    });   

}); 

工作样本:http://jsfiddle.net/2CGWG/3/

1

你可以试试这个,以及

$(document).ready(function(){ 
    $('.my-response','.both').each(function(){alert($(this).val())}); 
});​ 

这里是demo

0

这效果最好!

$(function(){ 

$('.my-response').each(function() {alert($(this).val());}); 

}); 

Demo