jQuery:选择包含给定元素的HTML表 [英] JQuery: select an HTML table that contain a given element

查看:93
本文介绍了jQuery:选择包含给定元素的HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下HTML

Let's say I have the following HTML

<table id = "mytable">
  <tr>
    <th>Hiring Manager</th>
    <td><textarea id = "textComments" cols = "15"/></td>
  </tr>
</table>

在上面的标记中,我想添加以下行

From the above markup, I'd like to append the following row

<tr>
   <td></td>
   <td>
       <span class = "CharCounter">
           <span id="lblCharCounter">Label</span>
           characters (500 max)
       </span>
   </td>
</tr>

我希望能够从文本区域中选择表格.

I want to be able to select the table, from the textarea.

感谢您的帮助

推荐答案

如果要在表中添加另一行,请找到textarea,然后慢慢进行操作,直至达到所需的目的.要返回一个元素,只需再次使用.parent().

If you want to add another row inside of the table, find the textarea, and slowly work your way until you get to the point you want. To go back an element, simply use .parent() again.

$('#textComments').parent().parent().after('
    <tr>
       <td></td>
       <td>
         <span class = "CharCounter">
           <span id="lblCharCounter">Label</span>
           characters (500 max)
         </span>
      </td>
   </tr>'
); 

这篇关于jQuery:选择包含给定元素的HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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