::jQuery::如果文本包含链接(http/https),则此链接应为图像源

toe95027  于 2022-10-09  发布在  jQuery
关注(0)|答案(0)|浏览(88)

我有一个表格数据与文本,图像网址等。

如果任何TD包含链接,则必须在img内写入此链接,src应为此文本

示例代码

<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>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题