是否可以获取 TD 的值并将其作为文本?
<td class="itemtd" value="58057" bgcolor="red"></td>
我似乎无法读取该值,甚至无法检查它是否存在,这是我到目前为止所尝试过的,但它不起作用
<script>
$(function(){
$('.itemtd').each(function(){
if ($(this).val() != '') {
$(this).append($(this).val());
}
});
});
</script>
最佳答案
您应该能够使用 jquery attr
和 html
获取值并将其放置在标记内:
<script>
$(function(){
$('.itemtd').each(function(){
if ($(this).attr('value') != '') {
$(this).html($(this).attr('value'));
}
});
});
</script>
关于javascript - 将 TD 值作为其文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36016495/