将输入值应用于其所有td innerhtml [英] apply values of inputs to all its td innerhtml

查看:128
本文介绍了将输入值应用于其所有td innerhtml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在内部输入时更改所有td的innerhtml,我的意思是获取输入的值并将其应用到它的td innerhtml,例如,这里是表及其输入内部:

is it possible to change the innerhtml of all the td when it has the input inside, i mean to take the input's value and apply it to it's td innerhtml, for example, here's the table and its input inside:

<table>
 <tr>
  <td><input value="test" /></td>
  <td>123</td>
 </tr>
</table>

将其改为:

<table>
 <tr>
  <td>test</td>
  <td>123</td>
 </tr>
</table>

?请注意td innerhtml没有改变:)谢谢大家的帮助! ;)

for all of the td and input values without applying id's and classes?! please pay attention that td innerhtml didnt change :) thank you all for the help! ;)

推荐答案

这很简单。

首先命名你的表(轻松找到)。

Name your table first (to find it easily).

<table id="the_table">
 <tr>
  <td><input value="test" /></td>
 </tr>
</table>

然后你可以这样做:

$('#the_table td input[type="text"]').each(function() {
  var val = $(this).val();
  $(this).parent('td').html(val);
});

现场演示


  1. 查找<$ p $ c>< td> 中的所有输入都在此特定表格中。

  1. find all inputs that are within <td> that are in this certain table.

每个输入:

2.1从输入中检索值

2.1 retrieve value from the input

2.2查找<$ c输入的第一个父项$ c>< td> 标记并将其 innerHTML 设置为该值

2.2 find first parent of the input that is a <td> tag and set its innerHTML to that value

这篇关于将输入值应用于其所有td innerhtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆