我检查了其他相同的帖子,我做了很多改动,但似乎没有任何效果!我的目标是在html中创建一个表单,当用户提交点击飞机或船舶的数据时,将其重新定向到另一个表单A,其余部分(火车,公共汽车)重定向到表单B.为此,我有javascript中的foo函数。但是当我点击提交按钮时,onclick功能不起作用!有什么想法吗?
<HTML>
<HEAD> <title> Ticket Choice </title></HEAD>
<SCRIPT type="text/javascript">
function foo(){
alert("Submit button clicked!");
if (document.getElementById('buttonCheck1') ||
(document.getElementById('buttonCheck2')) {
document.forms['form0'].action="C:/Users/Jo/workspace/myAskisisDir/WebContent/formA.html";
}
else {
document.forms['form0'].action="C:/Users/Jo/workspace/myAskisisDir/WebContent/formB.html";
}
}
</SCRIPT>
<BODY>
<h1> Choice of transfer ticket </h1>
<FORM id = "form0" method = "GET">
<fieldset title = "plane">
<input type = "radio" onclick = "javascript:IsCheck(1);" name = "button" id =
"buttonCheck1"> PLANE <br>
</fieldset>
<fieldset title = "ship">
<input type = "radio" onclick = "javascript:IsCheck(2);" name = "button" id =
"buttonCheck2"> SHIP <br>
</fieldset>
<fieldset title = "train">
<input type = "radio" onclick = "javascript:IsCheck(3);" name = "button" id =
"buttonCheck3">train<br>
</fieldset>
<fieldset title = "bus">
<input type = "radio" onclick = "javascript:IsCheck(4);" name = "button" id =
"buttonCheck4"> bus <br>
</fieldset>
<input type="submit" value="submit" onclick = "foo();"/>
<input type = "reset"/>
</FORM>
</BODY>
</HTML>
答案 0 :(得分:0)
语法错误
if (document.getElementById('buttonCheck1')||(document.getElementById('buttonCheck2')) {
应该是
if (document.getElementById('buttonCheck1') || document.getElementById('buttonCheck2')) {
现在你可以感到愚蠢:P
尝试一下,这会触发onclick功能。干杯!