求助:jquery循环td,获取td中元素的问题

zhangxiaolei 2009-08-23 05:44:16
<table>
<tr>
<td>第一行</td>
<td class="td_text">
<select>
<option value=""></option>
<option value="02" selected>a</option>
<option value="03">b</option>
<option value="01">c</option>
</select>
</td>
</tr>
<tr>
<td>第二行</td>
<td class="td_text"><input type="text" id="txt_road" name="txt_road" value="helloworld"/></td>
</tr>
</table>
以上是页面内容,我想让td(class=td_text)的值等于当前元素的值,即下面结果
<table>
<tr>
<td>第一行</td>
<td class="td_text">b</td>
</tr>
<tr>
<td>第二行</td>
<td class="td_text">helloworld</td>
</tr>
</table>

我的思路是:
$("td[class='td_text']").each(function(){
  $(this).html();//但此处不知道怎么获取td中子元素
});
请xdjm帮帮忙噢.....


...全文
1160 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ary2010 2010-06-17
  • 打赏
  • 举报
回复
$("td[class='td_text']").each(function(idx1){
$(":input", $(this)).each(idx2){
});
});
禽兽v5 2009-08-24
  • 打赏
  • 举报
回复
$("td[class='td_text']").each(function(idx1){
$(":input", $(this)).each(idx2){
});
});
hookee 2009-08-23
  • 打赏
  • 举报
回复

<script src="js/jquery-1.3.2.js"></script>
<script>
window.onload=function(){
$(".td_text").each(function(){
if($(this).children("input").length>0) $(this).html($(this).children("input, input:checked").val());
else if($(this).children("select").length>0) $(this).html($(this).children("select").children("option:selected").html());
});
}
</script>
<table>
<tr>
<td>第一行 </td>
<td class="td_text">
<select>
<option value=""> </option>
<option value="02" selected>a </option>
<option value="03">b </option>
<option value="01">c </option>
</select>
</td>
</tr>
<tr>
<td>第二行 </td>
<td class="td_text"> <input type="text" id="txt_road" name="txt_road" value="helloworld"/> </td>
</tr>
</table>
mrshelly 2009-08-23
  • 打赏
  • 举报
回复

$("td[class='td_text']").each(function(idx1){
$("input,select", $(this)).each(idx2){
});
});

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧