Javascript 我的php表单中的所有链接都直接指向表单操作

Javascript 我的php表单中的所有链接都直接指向表单操作,javascript,php,html,forms,Javascript,Php,Html,Forms,这是我的以下代码 <form class="form-horizontal" id="tambah_gps" name="tambah_gps" method="POST" action="../controller/add_gps.php"> <table> <tr style="height:40px"> <td>Nama User</td&g

这是我的以下代码

<form class="form-horizontal" id="tambah_gps" name="tambah_gps" method="POST" action="../controller/add_gps.php">
              <table>
                <tr style="height:40px">
                  <td>Nama User</td>
                  <td style="width:20px"> : </td>
                  <td><input class="form-control" type="text" name="nama_user" placeholder=" User Name" style="width:300px" readonly></td>
                  <td>&nbsp&nbsp<a href="javascript:void(0)" onClick=window.open("pilih_user.php","Ratting","width=1000,height=400,left=200,");><button class="btn btn-primary">Choose User</button></a></td>
                </tr>
                <tr style="height:40px">
                  <td>Vehicle ID</td>
                  <td style="width:20px"> : </td>
                  <td colspan="2"><input class="form-control" type="text" name="no_polisi" placeholder=" Nomor Polisi Kendaraan"></td>
                </tr>
                <tr style="height:40px">
                  <td>Car brand</td>
                  <td style="width:20px"> : </td>
                  <td colspan="2"><input class="form-control" type="text" name="merk_mobil" placeholder=" Merk Mobil"></td>
                </tr>
                <tr style="height:40px">
                  <td>Color</td>
                  <td style="width:20px"> : </td>
                  <td colspan="2"><input class="form-control" type="text" name="warna" placeholder=" Warna"></td>
                </tr>
                <tr style="height:40px">
                  <td>GPS Number</td>
                  <td style="width:20px"> : </td>
                            <td colspan="2"><input class="form-control" type="text" name="no_telp_gps" placeholder=" nomor telepon GPS"><td>
                </tr>
                <tr style="height:40px">
                  <td>Time Zone/td>
                  <td style="width:20px"> : </td>
                  <td colspan="2"><input class="form-control" type="text" name="zona_waktu" value="GMT (Default)" placeholder=" Zona Waktu" readonly></td>
                </tr>
              </table>
              <div class="modal-footer">
                <button  class="btn btn-default" data-dismiss="modal">Cancel</button>
            <input type="submit" name="sumbit" value="Save" class="btn btn-primary">
</div>
<form>
我制作的表单有3个按钮:1个保存按钮、1个取消按钮和1个选择用户名的按钮。。如果单击选择用户名的按钮,将打开包含用户列表的新窗口。这个按钮很好用。但无论何时单击,页面总是指向表单操作,就像单击“保存”按钮一样。谁能告诉我我的代码有什么问题吗?谢谢你…

首先,你可以使用你的内部,后者有javascript:void0作为href。如果不需要href,那么就没有必要使用它

第二,nbps实体必须以结束

onclick中的第三个javascript必须用括起来。javascript语句中应使用单引号

最后一点:你们必须告诉我你们想要的是什么:按一下按钮!使用type='button'

因此,选择用户按钮的行如下所示:

<td>&nbsp;&nbsp;<button type="button" class="btn btn-primary" onClick="window.open('pilih_user.php','Ratting','width=1000,height=400,left=200');">Choose User</button></a></td>

您将它们都作为btn btn主节点,尝试更改其中一个,看看发生了什么。您的代码没有问题。这就是html表单的行为。您单击表单中的一个按钮,它将提交该表单。@jim:css类与您单击按钮时发生的事情无关。它们只是样式设置规则…将按钮移到窗体外部,然后将其选定值回显到窗体内部的字段。将按钮设置为标记,而不是该按钮,并将其样式设置为按钮。按钮在html表单中往往表现为提交者,尽管在您的情况下不应该这样。你的代码看起来不错。