尝试使用php代码附加html列表?
我将这个php脚本放在一个html列表元素中,如果变量?pw=“password”,用户可以直接从网页编辑html元素。我希望用户也有能力添加列表项供他们编辑,有没有办法使用php在html中附加另一个列表项?我知道你可以在javascript中使用.append()。。。这就是我所说的php脚本:尝试使用php代码附加html列表?,php,javascript,html,Php,Javascript,Html,我将这个php脚本放在一个html列表元素中,如果变量?pw=“password”,用户可以直接从网页编辑html元素。我希望用户也有能力添加列表项供他们编辑,有没有办法使用php在html中附加另一个列表项?我知道你可以在javascript中使用.append()。。。这就是我所说的php脚本: <li> <?php if ($_POST['pw']!="") { $pw=($_POST['pw']); }
<li>
<?php
if ($_POST['pw']!="") {
$pw=($_POST['pw']);
} else {
$pw=($_GET['pw']);
}
$newcontent2=($_POST['newcontent2']);
$filelocation2 = "content/event2-1.txt";
if (!file_exists($filelocation2)) {
echo "Couldn't find datafile, please contact the administrator. huberwb@g.cofc.edu";
} else {
$newfile2 = fopen($filelocation2,"r");
$content2 = fread($newfile2, filesize($filelocation2));
fclose($newfile2);
}
$content2 = stripslashes($content2);
$content = htmlentities($content2,ENT_HTML5);
/*set password */
$pass = "password";
if (!$pw || $pw != $pass){
$content2 = nl2br($content2);
echo $content2;
} else {
if($newcontent2){
$newcontent2 = stripslashes($newcontent2);
$newfile2 = fopen($filelocation2,"w");
fwrite($newfile2, $newcontent2);
fclose($newfile2);
echo "Text has been edited.";
echo "<form><input type= 'submit' value='see changes' class='button'/></form>";
} else {
echo "<form method='post'> <textarea name ='newcontent2' style= 'width:100px; height:20px; border: 3px solid # ccc; font-family: sans-serif; font-size:small;' cols ='auto' rows='auto' wrap='virtual'>";
echo $content2;
echo "</textarea>
<input type='hidden' name='pw' value= '".$pass."' />
<br /><input type='submit' value='edit' class='button' />
</form>";
}
}
?>
</li>
PHP在页面加载时呈现在服务器端
用户的更改(即列表中的新项)只能由PHP通过新请求添加。这可以通过多种方式完成,例如,整页刷新,其中表单发送请求,页面使用新列表条目重新加载。或者,您可以使用JavaScript/jQuery将表单发送到PHP,然后将一些返回html返回到列表的append()
希望有帮助