0

我使用了淘汰赛并从我的 ModelView 模板中取回了这些...

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

我怎样才能做到这一点?

谢谢

4

3 回答 3

2

试试这个

$(function(){

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

});

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

于 2012-07-11T19:43:51.497 回答
1

你也可以试试这个

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

这是演示

于 2012-07-11T19:47:22.043 回答
0

这效果最好!

$(function(){

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

});

演示

于 2012-07-12T19:33:06.943 回答