Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行Javascript函数和PHP_Javascript_Php - Fatal编程技术网

运行Javascript函数和PHP

运行Javascript函数和PHP,javascript,php,Javascript,Php,我正在处理联系人页脚。HTML如下所示: <form action="indexTest.php" method="post"> <input spellcheck="false" class="first" type="text" name="name" placeholder="name"> <input spellcheck="false" class="first" type=

我正在处理联系人页脚。HTML如下所示:

<form action="indexTest.php" method="post">
                    <input spellcheck="false" class="first" type="text" name="name" placeholder="name"> 
                    <input spellcheck="false" class="first" type="text" name="email" placeholder="email"> 
                    <textarea rows="5" spellcheck="false" class="last" type="text" name="message" placeholder="message"></textarea> 
                    <input type="submit" name="submit" value="" id="button" onclick="banner()">    
                </form> 

现在,如果单击“提交”,PHP文件正在运行。但正如您在代码中看到的,您会看到“onclick=“banner()”。但这不起作用。只有PHP起作用。它希望同时运行Javascript函数和PHP

我想实现这一点,如果您单击“提交”,PHP文件将运行,Javascript将显示一条横幅。

您可以使用
onsubmit()
函数,该函数首先执行函数,然后操作事件将起作用

<form onsubmit="return banner();" action="indexTest.php" method="post"  name="theForm">
                        <input spellcheck="false" class="first" type="text" name="name" placeholder="name"> 
                        <input spellcheck="false" class="first" type="text" name="email" placeholder="email"> 
                        <textarea rows="5" spellcheck="false" class="last" type="text" name="message" placeholder="message"></textarea> 
                        <input type="submit" name="submit" value="" id="button">    
                    </form> 

                    <script type="text/javascript">
                        function banner(){
                            alert('working');
                            document.theForm.submit();
                        }
                    </script>

功能横幅(){
警报(“工作”);
document.theForm.submit();
}

希望它能帮助您将javascript函数附加到表单onsubmit事件

<form action="indexTest.php" method="post" onsubmit="banner()">
                <input spellcheck="false" class="first" type="text" name="name" placeholder="name"> 
                <input spellcheck="false" class="first" type="text" name="email" placeholder="email"> 
                <textarea rows="5" spellcheck="false" class="last" type="text" name="message" placeholder="message"></textarea> 
                <input type="submit" name="submit" value="" id="button">
</form> 


onclick事件可能只是在按钮类型为“button”时运行。

。当您提交表单时,它会将您重定向到
indexTest.php
,您的横幅将消失。您希望它如何同时执行这两个操作?