javascript - 其中一段被函数的输出替换
问题描述
在下面给出的代码中,一旦我们单击按钮,该段落就会被删除。为什么?
<html>
<head>
<script>
function func_1()
{
document.getElementById("show").innerHTML = "Hello World";
}
</script>
</head>
<body>
<h1>First</h1>
<button onclick="func_1()">Click here </button>
<p id="show"> Second</p>
</body>
</html>
解决方案
innerHTML 将所选 div 的内容替换为您提供给它的内容。因此,在您的情况下,删除“第二”并添加“Hello world”
推荐阅读
- amazon-web-services - 使用 Pulumi 获取私有子网 ID
- python - Selenium 找不到元素
- python - 在python while循环中访问JSON响应中的键值
- google-cloud-platform - 写入 Bigtable 时出现问题
- ajax - 对弹簧控制器的 Ajax 调用未返回成功
- linux - 如何允许元数据库在 Linux 上使用实例 IP
- spring - Spring security 和 keyclock - ServerHttpSecurity 错误
- android - 如何将卡与禁用的 FAB 重叠?
- r - 如何将 data.table 列的值列表绑定为额外的行
- python - 将数据框转置为列表的嵌套列表