这是我的代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Daftar Berita </title>
<meta http-equiv="content-type"
content="text/html; charset=utf-8"/>
</head>
<body>
<form method="post" action="">
<?php include 'formpencarian.html.php'; ?>
<div id="newssection" style="margin-top: 50px; clear: both; display: block;">
<?php include 'newssection.php'; ?>
</div>
<?php
if(isset($_POST["cari"])){
echo "<div id='searchsection' style='margin-top: 50px; clear: both; display: block;'>";
include 'search.php';
echo "</div>";
echo "<script>document.getElementById('newssection').style.display = 'none';</script>";
}
?>
<script>
function showMore(id){
document.getElementById('isi'+id).style.display = "block";
document.getElementById('more'+id).style.display = "none";
document.getElementById('less'+id).style.display = "block";
}
function showLess(id){
document.getElementById('isi'+id).style.display = "none";
document.getElementById('more'+id).style.display = "block";
document.getElementById('less'+id).style.display = "none";
}
function advancedSearch(){
document.getElementById('advanced').style.display = "none";
document.getElementById('searching').style.display = "block";
document.getElementById('no').style.display = "block";
}
function noSearch(){
document.getElementById('advanced').style.display = "block";
document.getElementById('searching').style.display = "none";
document.getElementById('no').style.display = "none";
}
</script>
</body>
</html>
基本上,search.php文件包含用于显示结果的mysql查询。
问题是,当这个页面重新加载时(因为我将POST变量发送到此页面),javascript不起作用。因此,我无法在结果页面上显示或隐藏某些div(因为结果页面的格式与此页面的格式相同)。
我做错了什么?请帮忙。感谢。
答案 0 :(得分:0)
在较大的JS部分中只有定义功能,但现在调用 - 要使它们在任何情况下运行,您需要调用它们,如:
noSearch();
advancedSearch();
此部分似乎与$_POST
检查无关
..
为了避免在search.php中没有调用它们,你应该从主文件中删除if(isset($_POST["cari"])){
检查并在search.php中进行检查