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就赋不了值,如果把$(":hidden",$(obj).parent().parent()).val($yourChoice); 放在前面,label就赋不了值了,请问该怎么给两个都赋值??
<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就赋不了值,如果把$(":hidden",$(obj).parent().parent()).val($yourChoice); 放在前面,label就赋不了值了,请问该怎么给两个都赋值??
<span id="GridView1_ctl02_chinese"> </span>
<input name="GridView1$ctl02$Hidden1" type="hidden" id="GridView1_ctl02_Hidden1" />
直接写成简单的html标签,不要使用asp.net的服务器端控件,设置id属性,用jquery的话就简单的多<span id="span1"> </span>
<input name="GridView1$ctl02$Hidden1" type="hidden" id="hidden1" />$("#span1").text(val);
$("#hidden1").val(val);
".div_chn"的内容已经改变了
我不知道$(obj).parent().parent()是什么
你想改变他什么 怎么有text还有val
$(".div_chn",$(obj).parent().parent()).text($yourChoice); 是把值给.div_chn和$(obj).parent().parent(),你说要把值赋给其父元素的父元素下的class为div_chn的label和label后面的hidden
应该是这么写吧
$(obj).parent().parent().find(".div_chn").text($yourChoice);
$(obj).parent().parent().find(":hidden").val($yourChoice);
如果说.div_chn和:hidden是唯一的就不用这么麻烦了
直接$(".div_chn").text($yourChoice); $(":hidden").val($yourChoice);