当我在Vanilla JS中选择<select>选项时如何更改<a> href

时间:2019-06-03 10:06:09

标签: javascript php html css

我正在尝试在a之间创建一个连接,并且如果我选择了VALUE,则的href将更改,那么在JavaScript中是否可以?

<html>
<head></head>
<body><select id="worldsize">
                           <option value="small_world" selected="">Small</option>
                           <option value="normal_world">Normal</option>
                           <option value="huge_world">Huge</option>
                           <option value="infinte_world" disabled="">Infinite</option>
                        </select>
<a name="a "class="for_a_button CreateANewWorldButton Checkout" href="?START_S" id="button_click">Create an new World</a>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

<html>
<head></head>
<body><select id="worldsize" onchange="change(this.value)">
                           <option value="small_world" selected="">Small</option>
                           <option value="normal_world">Normal</option>
                           <option value="huge_world">Huge</option>
                           <option value="infinte_world" disabled="">Infinite</option>
                        </select>
<a name="a "class="for_a_button CreateANewWorldButton Checkout" href="?START_S" id="button_click">Create an new World</a>


<script>

function change(val){
  document.getElementById("button_click").href= val;
}

</script>

</body>
</html>