【发布时间】:2018-08-10 03:37:19
【问题描述】:
长期以来,我一直在尝试让一个按钮出现在网页上,并使该按钮所指向的链接根据所选的单选按钮而改变。但是,到目前为止,我的网页上除了单选按钮之外什么都没有出现。 到目前为止,这是我的代码:
<div id="quick-book">
<script>
if (document.getElementById("radio-restaurant").checked){
document.getElementById("button").innerHTML = "<a href='./restaurant.html'>Submit</a>";
} else if (document.getElementById("radio-hotel").checked){
document.getElementById("button").innerHTML = "<a href='./hotel.html'>Submit</a>"
}
</script>
<form name="frmRadio" id="radio-buttons" action="">
<input type="radio" id="radio-restaurant" name="option" onclick="document.getElementById('radio-buttons').action='';">Restaurant<br>
<input type="radio" id="radio-hotel" name="option" onclick="document.getElementById('radio-buttons').action='';">Hotel<br>
</form>
<div name ="button">
</div>
</div>
我希望这里有人可以帮助指导我正确的方向!
【问题讨论】:
-
请不要通过破坏您的帖子为人们增加工作量。通过在 Stack Exchange (SE) 网络上发帖,您已在 CC BY-SA 3.0 license 下授予 SE 分发该内容的不可撤销的权利(即无论您未来的选择如何)。根据 SE 政策,帖子的非破坏版本是分发的版本。因此,任何破坏行为都将被撤销。
标签: javascript html forms radio-button