提交按钮不响应操作

时间:2013-08-28 05:58:07

标签: php javascript jquery html

我有一个奇怪的问题!!我的提交按钮没有回复行动!!!

我有这段代码:

<script type="text/javascript">
    function save_contact_information() {

        document.getElementById('User_Finder').action = "Controler/controller_page.php?button=save_contact_information";

    }
</script>
<form id="User_Finder" action="User_Finder.php?ID_CV_User=<?php print $ID_CV_User ?>&&change_profile=ok"
method="post" enctype="multipart/form-data">

    <input type="submit" id="CI_BT_Save" onclick="save_contact_information()"
    name="BT_PI_Save" value="Save" style="position:absolute;left:12px;top:333px;width:96px;height:25px;z-index:342;">

</form>

如果我点击按钮保存,什么都不会改变! 我将函数'save_contact_information()'的代码更改为:

function save_contact_information() {
    alert("ok1");
    document.getElementById('User_Finder').action = "Controler/controller_page.php?button=save_contact_information";
    alert("ok2");
}

现在,如果我单击按钮保存,将显示2个警报:ok1 + ok2但是此行: document.getElementById('User_Finder').action ="Controler/controller_page.php?button=save_contact_information";没有任何反应!!!

有没有人知道这个ODD问题!!!

5 个答案:

答案 0 :(得分:0)

它是一个表单,所以你必须添加event.preventDefault()

修改 这样做

function save_contact_information() {
    alert("ok1");
event.preventDefault();
    document.getElementById('User_Finder').action = "Controler/controller_page.php?button=save_contact_information";
    alert("ok2");
document.getElementById('User_Finder').submit();
}

答案 1 :(得分:0)

function save_contact_information() {
alert("ok1");
                document.getElementById('User_Finder').action ="Controler/controller_page.php?button=save_contact_information";
alert("ok2");
  document.getElementById('User_Finder').submit(); //here form submit with your action


            }

答案 2 :(得分:0)

document.getElementById("User_Finder").submit();

答案 3 :(得分:0)

将您的功能更改为:

function save_contact_information() {
var myForm = document.getElementById('User_Finder');
myForm.action ="Controler/controller_page.php?button=save_contact_information";
myForm.submit();
}

<强>详细信息:

由于您的按钮正在调用另一个功能,因此只有在下一次单击时才会调用新操作。您也可以通过手动调用提交功能再次触发表单的提交。

  

您可能还需要将myForm变量声明为以避免繁重   每当您尝试搜索表单时,DOM操作

答案 4 :(得分:0)

而不是点击提交按钮,使用表单标签中的提交返回。这是更好的方法。它会起作用。

<form id="User_Finder" action="User_Finder.php?ID_CV_User=<?php print $ID_CV_User ?>&&change_profile=ok" method="post" onsubmit="return save_contact_information()" enctype="multipart/form-data">

   <input type="submit" id="CI_BT_Save" name="BT_PI_Save" value="Save" style="position:absolute;left:12px;top:333px;width:96px;height:25px;z-index:342;">

</form>


<script type="text/javascript">
function save_contact_information() {

    document.getElementById('User_Finder').action = "Controler/controller_page.php?button=save_contact_information";
    return true;

}
</script>

尽量避免提交按钮的onclick事件