如何使一个按钮在单击时显示另一个按钮
How to make a button show another button onclick?
我正在尝试编写一个文本冒险,由于我大部分时间都是用PHP而不是Javascript进行编码,我想我忘记了Javascript的一切:p
无论如何,我正在寻找如何在单击另一个按钮后显示新按钮。我在"innerHTML"中有文本,所以我不知道如何使用它显示另一个按钮。这是我到目前为止的代码(当你点击新按钮时,它应该指向"b")
<script>
function one()
{
document.getElementById("a").innerHTML="You feel something on the ground, and you think it's a stick.";
}
function two()
{
document.getElementById("b").innerHTML="You pick up the stick. It might be useful for something.";
}
</script>
<div style="margin-left:15px; width:200px; margin-top:100px;">
<button onclick="one()">Feel around the cave</button>
</div>
<div style="margin-left:255px; width:200px; margin-top:-15px;">
</div>
<div id="entire" style="margin-left:490px; margin-top:-22px; width:400px; height:600px;"><div id="b"></div><div id="a"></div></div>
在页面末尾,在脚本标记中添加以下代码
var a = document.getElementById('a');
a.addEventListener('click', function () { two()});
您应该查看jQuery
尝试将其添加到您的one()函数中:
var newButton = '<button onclick="two()">Pick up stick</button>';
document.getElementById("a").innerHTML="You feel something on the ground, and you think it's a stick."+newButton;
这将把按钮放在"a"分区内。
相关文章:
- Jquery/Javascript:通过按下按钮显示数组中的随机图像
- 类似FB的按钮显示在页面上,但不会在同一页面上弹出
- 单击javascript按钮显示/隐藏Div元素
- 单击按钮显示不同的文本,重复第一个文本
- C3.js通过单击按钮显示工具提示
- 单击按钮显示重新单击消失
- 点击浏览器的“后退”按钮显示的是JSON而不是HTML(使用Rails和d3.js)
- 尝试从单选按钮显示的JSON数组中调用多个对象
- 在youtube视频中单击按钮显示图像
- 使用HTML和Javascript,使用4个单选按钮显示和隐藏输入字段
- 如何在javascript中使两个按钮显示在一起
- 如何使用按钮显示/隐藏潜水
- 使用不起作用的按钮显示和隐藏
- facebook点赞按钮显示数以万计的点赞
- 流星:点击按钮显示一些东西
- jQuery按钮显示/隐藏类,如果存在类
- 如何让我的 ckEditor 菜单按钮显示在两行而不是四行上
- 如何让我的移动菜单按钮显示和隐藏导航栏,以及在负空间中单击时隐藏
- 网格中的拆分按钮显示在行后面 - 剑道 UI
- Dijit 按钮显示图标,但不以编程方式显示标签