我正在尝试从 td 中提取文本,如此处所述 Replacing a part of text inside a td
$('.my-table tr').each(function() {
var contact = $(this).find('td').eq(1)[0].childNodes[0].nodeValue;
$(this).find('td').eq(1).contents()[0].data = contact.substring(0,10);
});
但是 contact.substring(0,10);似乎不起作用,它只是显示为空。
我该如何解决这个问题?
最佳答案
试试这个:
$('.my-table tr').each(function() {
var contact = $.trim($(this).find('td').eq(1)[0].childNodes[0].nodeValue);
if(contact != '')
{
var value = contact.substring(0,10);
alert(value);
$(this).find('td').eq(1).contents()[0].data = contact.substring(0,10);
}
});
您收到的警报值是多少?或者您收到任何警报吗??
关于javascript - 子字符串不适用于 childNodes[0].nodeValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13763956/