尝试根据选择的单选按钮更改语句中的 href 引用
<ul class="size_selector">
<li class="top"><input type="radio" class="radioselect" name="id" id="test1" value="test1" /><label for="test1">1</label></li>
<li class="top"><input type="radio" class="radioselect" name="id" id="test2" value="test2"/> <label for="test2">2</label></li>
<li class="top"><input type="radio" class="radioselect" name="id" id="test3" value="test3"/> <label for="test3">3</label></li>
<li class="top"><input type="radio" class="radioselect" name="id" id="test4" value="test4"/> <label for="test4">4</label></li>
</ul>
<a id="shopCart" href="#">
Take me to your leader
</a>
查询
$("input[type='radio']").change(function(){
switch($(this).val()) {
case "test1" :
document.getElementById("shopCart").href="http://yahoo.com";
break;
case "test2" :
document.getElementById("shopCart").href="http://bing.com";
break;
case "test3" :
document.getElementById("shopCart").href="http://google.com";
break;
case "test4" : document.getElementById("shopCart").href="http://stackoverflow.com";
break;
};
});
最佳答案
您正在使用 JQuery,但没有将其链接进来。
设置 -> JavaScript
在 https://code.jquery.com/jquery-3.1.0.min.js 中添加此链接.
关于javascript - 使用 switch 语句选择单选按钮时更改 href 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38947982/