<tr>
<td>
                        <div class="line">
                            <div class="div_chn"><span id="GridView1_ctl02_chinese"></span><input name="GridView1$ctl02$Hidden1" type="hidden" id="GridView1_ctl02_Hidden1" /></div>
                            <div class="div_kuohao"><span id="GridView1_ctl02_Label2">)</span></div>
                            
                        </div>
                        <div>
                  &nbsp;&nbsp;
                            <span id="GridView1_ctl02_answer1" class="option"  onclick="choiceAnswer(this)" style="display:inline-block;width:120px;"> 发烧,体温</span>
                            <span id="GridView1_ctl02_B" class="option" style="display:inline-block;width:10px;">B.</span>
                            <span id="GridView1_ctl02_answer2" class="option"  onclick="choiceAnswer(this)" style="display:inline-block;width:120px;"> 迟到</span>                         
                        </div>
                    </td>
</tr>function choiceAnswer(obj)
{
    $yourChoice=$(obj).text();
    $(".div_chn",$(obj).parent().parent()).text($yourChoice);
    $(":hidden",$(obj).parent().parent()).val($yourChoice);
}想要点击answer1或answer2时,将其值赋到label和hidden上,明明hidden和label处在同一层,我的代码却只能把值赋到label,而hidden却不行??

解决方案 »

  1.   

    jQuery selector 会 select 
    <div class="div_chn"> <span id="GridView1_ctl02_chinese"> </span> <input name="GridView1$ctl02$Hidden1" type="hidden" id="GridView1_ctl02_Hidden1" /> </div>
                                <div class="div_kuohao"> <span id="GridView1_ctl02_Label2">) </span> </div>
    after $(".div_chn",$(obj).parent().parent()).text($yourChoice):<div class="div_chn"> some value ... </div>
    因为hidden被洗了, 所以无法赋予
      

  2.   


    $('#GridView1_ctl02_chinese').text($yourChoice);
    $(':hidden').val($yourChoice);或者:$('.div_chn').html($yourChoice + $('.div_chn').html());
    $(':hidden').val($yourChoice);
      

  3.   

    $(':hidden')不是选择所有的hidden吗,我动态生成了很多hidden的,我是要点击每个label,就将它的值赋值给他父元素的父元素下的hidden!!
      

  4.   

    动态生成的,应该是没找到hidden吧~!
      

  5.   

    父元素的父元素下的hidden (according to yr html structure):
    $(obj).parents('td:first').find(':hidden').val($yourChoice);