2017-02-15 5 views
0

Ich kann eine externe Seite im DOM öffnen.Eingabe mit jquery-Variable füllen (Eingabe HTML-Code empfangen)

Aber ich versuche, alle Tags, um das Kindes von einem div zu holen und es an das JavaScript-Variable speichern und drucken dann die Variable in dem Eingangswert

Ich brauche in Eingabe all HTML-Inhalt des div speichern und das Kind tags:

 <form method="POST" action="test.php"> 
       <input id="content" type="text" name="content" value="<script>document.write(content)</script>"> 
       <input type="submit" value="submit"> 
     </form> 


     <div id="mydiv"></div>// here load external page 


     <script> 

     $(document).ready(function(){ 

      $("#mydiv").load("index.html"); // load external page in Dom 

      var content = $(this).closest('#div1'); 
      /* find all parents tags e content of div id="div1" 
      (This is inside the external index.html file) */ 

     }); 

     </script> 

ich erhalte es nicht, ich weiß nicht, wohin ich gehe falsch im Code oben

Dank

Antwort

0
//try like below 
<form method="POST" action="test.php"> 
      <input id="content" type="text" name="content" value=""> 
      <input type="submit" value="submit"> 
    </form> 


    <div id="mydiv"></div>// here load external page 


    <script> 

    $(document).ready(function(){ 
     $("#mydiv").load("index.html"); 
     var loadFile = load("index.html"); 
     var content = $(loadFile).find('#div1').html(); 
     $('#content').val(content); 

    }); 

    </script> 
0

Sie benötigen callback Funktion verwenden, um die geladenen Inhalte anzuzeigen/erkunden mit $.fn.load

$(document).ready(function(){ 
    $("#mydiv").load("index.html", function(data){ 
     // assuming #div1 is inside "index.html" 
     var content = $(data).find("#div1"); 
    }); 
}); 
Verwandte Themen