You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用jQuery将表格td中的图片URL转换为img标签?

需求:将表格中含HTTP/HTTPS链接的TD内容转为IMG标签

我有一个包含文本、图片URL等内容的表格数据。若任意<td>元素中包含http/https链接,需将该链接作为src属性值包裹在<img>标签内。


示例代码

<table cellpadding="0" cellspacing="0" width="100%">
   <tbody>
      <tr>
         <td>1</td>
         <td>https://amp.dev/static/samples/img/product1_640x426.jpg</td>
         <td>Apple</td>
         <td>1.99</td>
      </tr>
      <tr>
         <td>2</td>
         <td>https://amp.dev/static/samples/img/product2_640x426.jpg</td>
         <td>Orange</td>
         <td>0.99</td>
      </tr>
   </tbody>
</table>

期望输出

<table cellpadding="0" cellspacing="0" width="100%">
   <tbody>
      <tr>
         <td>1</td>
         <td><img src="https://amp.dev/static/samples/img/product1_640x426.jpg" /></td>
         <td>Apple</td>
         <td>1.99</td>
      </tr>
      <tr>
         <td>2</td>
         <td><img src="https://amp.dev/static/samples/img/product2_640x426.jpg" /></td>
         <td>Orange</td>
         <td>0.99</td>
      </tr>
   </tbody>
</table>

内容的提问来源于stack exchange,提问作者Reddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 16:01:32