参考内容 1:
用jquery 获取div中不在其他标签内的文字
<div id="price">
<small>$</small>
256
</div>
我要更改数字,怎么获取到256
代码:
$("div#price").prop("lastChild").nodeValue
参考内容2:
jquery取元素内容怎么排除span标签
<td>6666<span class="copy">[复制]</span></td>
我要实现点击复制 弹出6666 内容
代码:
<script type="text/javascript" src="jquery-1.8.0.min.js"></script> <script> $ (function () { $ (".copy").bind ("click", function () { var test = $($ (this).prop ('previousSibling')).text(); console.log (test); }) }) </script>
项目中的需求:
<tr id="tr">
<td class="t-left">
<span class="prev_span">
<span class="vsStyle_node vsStyle_blank"></span>
</span>
<span arrow="true" class="vsStyle_active_node vsStyle_shut"></span>
抚州市
</td>
<td>其他内容1</td>
<td>其他内容</td>
</tr>
需求:需要将抚州市更换成其他字符。不改变td里的样式。
//赋值操作 $("#tr")效果一样
$("tr[id='tr']).find("td:first").prop("lastChild").nodeValue="赣州市";
注意:项目中使用jQuery1.4.4会找不到prop方法,使用1.9后问题解决。