onclick输入类型submit

onclick input type submit

本文关键字:submit 类型 输入 onclick      更新时间:2023-09-26

在一个表单中,我有一个<iframe>,它包含一个PHP文件(editor.PHP)。这个PHP文件包含一个HTML表单。

好吧,当我做"提交表单"时,我会调用相同的PHP文件,例如main.PHP。当我按下提交按钮时,我有一个"onclick方法",它在editor.php中调用一个Javascript函数

我的问题是主表单执行正确,但第二个表单没有。

在editor.php形式的第二个循环中,它什么也没收到。

**Check this way it will work as you expected**
//main.php
<html>
<head>
<script type="text/javascript">
    function validateMain()
    {
       alert('main'); 
    }
    function validateSub()
    {
        alert('sub'); 
    }
</script>
</head>
<body>  
<form id="main"  onsubmit="return validateMain();">
        <input type="text" name="first" id="first"/>
        <input type="submit" value="Submit Main"/> 
 </form>
 <iframe name="ifr-form" id="ifr-form" src="test.html"></iframe> 
</body>
</html>
//test.html the second form included through iframe
    <!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div>

 <form id="sub" onclick="return window.top.validateSub();">
        <input type="text" name="first" id="second"/>
        <input type="button" value="Submit Sub" /> 
      </form>
        </div>
    </body>
</html>

您必须检查php和iframe是否兼容,据我所知,我不认为frames和php提供任何输出,希望这有帮助。