[英]Copy text/content from td to another td by condition
I would like to copy td to another td by condition. 我想按条件将td复制到另一个td。
I do not want use some function on click or press key.. i need function on loading. 我不想在单击或按下键时使用某些功能。我需要在加载时使用功能。
For example - Is in td id-'hello' character 1? 例如-在td id-“ hello”字符中是否为1? If yes, move all content to td 'hello_copy'
如果是,请将所有内容移至td'hello_copy'
<td id="hello">
number 1 is good </td>
<td id="hello">
数字1很好 </td>
<td id="hello_copy></td>
RESULT: 结果:
<td id="hello">
number 1 is good </td>
<td id="hello">
数字1很好</td>
<td id="hello_copy>`number 1 is good`</td>
To achieve this you can use the :contains
selector to find out if there's a 1
in the text of the #hello
cell, and then copy the value to the #hello_copy
cell, like this: 为此,您可以使用
:contains
选择器找出#hello
单元格文本中是否存在1
,然后将值复制到#hello_copy
单元格中,如下所示:
if ($('#hello:contains("1")')) $('#hello_copy').text($('#hello').text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr> <td id="hello">number 1 is good</td> <td id="hello_copy"></td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.