【发布时间】:2016-08-15 00:52:06
【问题描述】:
尝试根据选择的单选按钮更改语句中的 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>
jQuery
$("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;
};
});
【问题讨论】:
标签: javascript jquery input switch-statement href