<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>
<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却不行??
<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>
<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却不行??
<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被洗了, 所以无法赋予
$('#GridView1_ctl02_chinese').text($yourChoice);
$(':hidden').val($yourChoice);或者:$('.div_chn').html($yourChoice + $('.div_chn').html());
$(':hidden').val($yourChoice);
$(obj).parents('td:first').find(':hidden').val($yourChoice);