Heim  >  Fragen und Antworten  >  Hauptteil

Senden Sie das Iframe-Formular außerhalb des Iframes mit der Schaltfläche

<p>Ich habe eine contact.html-Datei, die einen iframe enthält: <code><iframe name="myframe" id="frame1" src="contact_inputs.php"></iframe> </code>, der nur die drei Eingabefelder in contact_inputs.php enthält. </p> <p>Ich möchte ein Formular in einer Iframe-Datei über eine Schaltfläche außerhalb des Iframes an php_form.php senden. </p> <blockquote> <p>Kontakt.html</p> </blockquote> <pre class="brush:php;toolbar:false;"><iframe name="myframe" id="frame1" src="contact_inputs.php"></iframe> <form action="php_form.php" method="post"> <input type="submit" name="DoIt" value="submit" </form></pre> <blockquote> <p>contact_inputs.php</p> </blockquote> <pre class="brush:php;toolbar:false;"><form> <input type="" name="cn"> <input type="" name="ex"> <input type="" name="cr"> </form></pre>
P粉316110779P粉316110779411 Tage vor534

Antworte allen(1)Ich werde antworten

  • P粉546179835

    P粉5461798352023-09-05 09:47:38

    在这里你可以尝试这个逻辑:

    function sub(ev) {
            ev.preventDefault();
            let frame1 = document.getElementById("frame1");
    
            let parser = new DOMParser();
            let doc = parser.parseFromString(frame1.innerHTML, "text/html");
    
            let iframeForm = doc.body.querySelector("form");
    
            console.log(iframeForm);
    
            //通过name属性访问表单输入字段的值
            console.log(iframeForm.cn.value);
          }
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
      </head>
      <body>
        <iframe name="myframe" id="frame1" src="contact_inputs.php">
          <form id="iframe1Form">
            <input type="" name="cn" value ="HELLO"/>
            <input type="" name="ex" />
            <input type="" name="cr" />
          </form>
        </iframe>
        <form onsubmit="sub(event)">
          <input type="submit" name="DoIt" value="submit" />
        </form>
    
        
      </body>
    </html>

    Antwort
    0
  • StornierenAntwort