简体   繁体   English

通过jQuery将文本追加到td单元格

[英]Append text to a td cell by Jquery

I need to append some text to the Name column by jquery, 我需要通过jquery在“ 名称”列中添加一些文本,
I tried this but no luck: 我尝试了这个,但是没有运气:

$(".ms-listviewtable").closest("tr").next().find(".ms-vb2:first").append("<p>test</p>");

JSFiddle Example JSFiddle示例

$(".ms-listviewtable").find(".ms-vb2:first").append("<p>test</p>");

See the fiddle 看到小提琴

JSFIDDLE 的jsfiddle

Use This it will work there 使用它会在那里工作

$(".ms-listviewtable tr:first td").eq(1).append("<p>test</p>");

DEMO DEMO

.closest() starts looking for the element traversing the DOM upwards, and you want to go downwards, inside your table. .closest()开始查找在表内部向上遍历DOM的元素,并且您想向下遍历DOM。

Use .find() instead: 使用.find()代替:

http://jsfiddle.net/w0Lrvo5y/3/ http://jsfiddle.net/w0Lrvo5y/3/

Try this : 尝试这个 :

$(".ms-listviewtable").find("tr:first").find(".ms-vb2:eq(1)").append("<p>test</p>");

Demo 演示

$(".ms-listviewtable > tbody > tr > td:nth-child(1)").hide();

Working Fiddle: http://jsfiddle.net/w0Lrvo5y/9/ 工作小提琴: http : //jsfiddle.net/w0Lrvo5y/9/

Basically just reach the parent element of the element you want to change and then access it using nth-child jQuery selector. 基本上,只需到达要更改的元素的父元素,然后使用nth-child jQuery选择器对其进行访问。

If you want to select which parent element to access you can use jQuery selector for that too. 如果要选择要访问的父元素,也可以使用jQuery选择器。

Hope it works for you. 希望对你有效。

If you just want to target the td containing 'Name' you could write 如果您只想定位包含“名称”的td,则可以编写

$(".ms-listviewtable .ms-vb2").first().append("<p>test</p>");

This will target the first td with the class .ms-vb2 within .ms-listviewtable 这将针对.ms-listviewtable中的类.ms-vb2的第一个td

Does this answer your question? 这回答了你的问题了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM