我们如何在JavaScript变量中获取带有HTML数据的div

<div id='myid'>
    <div>
        <ul>
            <li><strong>A</strong></li>
            <li><strong>B</strong></li>
            <li><strong>C</strong></li>
            <li><strong>D</strong></li>
            <li><strong>E</strong></li>
        </ul>
    </div>
</div>

How can I get a div with HTML data in a JavaScript variable?

You want to use php right ?

If it's the case you will have to use the DOMElement class http://php.net/manual/en/class.domelement.php

In your case:

$doc = new DOMDocument(); 
$doc->loadHTMLFile('YOUR HTML FILE PATH');    
$elem = $doc->getElementById('myid'); 

// loop through all childNodes, getting html        
$children = $elem->childNodes; 
foreach ($children as $child) { 
    $tmp_doc = new DOMDocument(); 
    $tmp_doc->appendChild($tmp_doc->importNode($child,true));        
    $innerHTML .= $tmp_doc->saveHTML(); 
} 

die(var_dump($innerHTML));

Using jQuery, if you want to store the html :

var html = $('#myid').html();

if you want to store the text only :

var html = $('#myid').text();