javascript - 当标签中没有 id 名称或特定类时,如何使用 javascript 向 HTML 添加文本?
问题描述
我想使用 javascript 在锚标记中向我的 HTML 页面添加一些文本,但该锚标记中没有 id、name 或 class。有没有办法做到这一点。示例代码如下。
<div>
<table>
<tbody>
<tr>
<th>
<span ng-if="smData.standard==smData.stdnr" class="ng-scope">
<a ng-click="m1(a,b)" class="ng-binding" href="/">
Hello.
</a>
</span>
</th>
</tr>
</tbody>
</table>
</div>
现在我想在 Hello(say world.) 中添加一些内容。
解决方案
使用属性选择器:
document.querySelector("a[ng-click='m1(a, b)']").innerText += " world.";
<a ng-click="m1(a, b)" class="ng-binding" href="/">Hello</a>
推荐阅读
- python - Discord.py 为用户添加角色
- c# - Spotify api 检索到的访问令牌不起作用
- laravel-5 - 如何在laravel中修复“试图获取非对象的属性'id'”?
- marklogic - 如何为 webdav 连接到 marklogic 创建只读用户
- css - 无法使用 Less mixin 创建动态类
- javascript - 我可以让 src 属性从服务器或调整服务器获取 base64 数据吗?
- excel - 是否有关于如何通过 Excel 中的 VBA 驱动 Office“公式编辑器”的文档?
- android - Scarlet Web 套接字库连接失败
- rust - rust statrs 样本不在范围内?
- python - 如何在 Python 中将浮点列表转换为 int 对列表?