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 に答える