javascript的Onclick函数提交按钮不工作

Onclick function of javascript for submit button not working

本文关键字:按钮 工作 提交 函数 Onclick javascript      更新时间:2023-09-26

我检查了其他相同的帖子,我做了许多更改,但似乎没有工作!我的目标是在html中创建一个表单,当用户提交数据时,点击飞机或船,将他重定向到另一个表单a,其余的(火车,公共汽车)重定向到表单b。但是当我点击提交按钮时,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>
语法错误

if (document.getElementById('buttonCheck1')||(document.getElementById('buttonCheck2')) {

应该是

if (document.getElementById('buttonCheck1') || document.getElementById('buttonCheck2')) {

现在你觉得自己很蠢:p

试试,这会触发onclick函数。干杯!