使用PHP附加标签 [英] Append tags using PHP
问题描述
我想使用PHP动态添加列表项。但是下面的代码什么也没做。
据我所知,每次刷新页面时,都应该创建并显示一个新的列表项。但这不会发生。
我尝试过:
<!DOCTYPE html>
< html>
< head>
< title>< / title>
< / head>
< body>
< ul id =test>
< li>样本< / li>
<?php
$ html = file_get_contents('index.php');
$ doc = new DOMDocument();
$ doc - > loadHTML($ html);
$ ul = $ doc - > getElementById('test');
$ li = $ doc - > createElement('li','Test');
$ ul - > appendChild($ li);
?>
< / ul>
< / body> ;
< / html>
html = file_get_contents('index.php');
doc = new DOMDocument();
doc - > loadHTML(
I want to add list items dynamically using PHP. But the code below does nothing.
According to me, everytime I refresh the page, a new list item should be created and displayed. But this isn't happening.
What I have tried:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul id="test">
<li>Sample</li>
<?php
$html = file_get_contents('index.php');
$doc = new DOMDocument();
$doc -> loadHTML($html);
$ul = $doc -> getElementById('test');
$li = $doc -> createElement('li', 'Test');
$ul -> appendChild($li);
?>
</ul>
</body>
</html>
html = file_get_contents('index.php');
doc = new DOMDocument();
doc -> loadHTML(
这篇关于使用PHP附加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!