选中的单选按钮已加载页面 [英] radio buttons on checked with page load
本文介绍了选中的单选按钮已加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下带有单选按钮的代码.问题是如果我选择一个按钮并单击提交",它会将我重定向到某个页面,但是在页面加载时,它需要检查单选按钮;如果我单击提交",它会发出警报,但是如果它也选择了它,则需要重定向到特定页面.页面.
Hi,
I have the following code with radio buttons. The problem is if i select a button and click submit it is redirecting me to a certain page but on page load it needs to check a radio button and if i click submit it gives an alert but if it selected also it needs to redirect to certain page.
<SCRIPT LANGUAGE="JavaScript">
function go(loc) {
if(loc ==''){
alert("please select a radio button");
}
else
window.location.href = loc;
}
function goTo(loc1){
document.form.selectedLoc.value = loc1;
}
</script>
</HEAD>
<BODY>
<form name="form">
<input type="radio" name="loc" checked="checked" onClick="goTo('google.html');" > google<br>
<input type="radio" name="loc" onClick="goTo('yahoo.html');"> yahoo<br>
<input type="radio" name="loc" onClick="goTo('facebook.html');"> facebook<br>
<input type="button" name="submit" value="submit" onclick="go(document.form.selectedLoc.value)"/>
<input type="hidden" name="selectedLoc" value=""></input>
</form>
推荐答案
您可以使用body标签内的onload
event调用javascript函数goTo(''google.html'');
.
You can call the javascript functiongoTo(''google.html'');
usingonload
event inside body tag.
<body onload="goTo('google.html');"></body>
或使用jQuery的另一种解决方案.
HERE 是参考.
Or another solution using jQuery.
HERE is the ref.
这篇关于选中的单选按钮已加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文