js代码,例如某点击函数:
function showSite()
{
str1=document.getElementById("time1").value;
str2=document.getElementById("time2").value;
window.location="managerindex.php?ptime1="+str1+"&ptime2="+str2;
}
传递参数格式(这里是两个参数,多个就照着第二个写下去就行):
window.location="managerindex.php?ptime1="+str1+"&ptime2="+str2;
window.location="PHP文件名?在PHP文件接收的参数名="+在js里面的参数名+"&在PHP文件接收的参数名="+在js里面的参数名;
在该php文件内任意地方都能接收到传递来的参数ptime1,ptime2,用$_GET[“ptime1”] , $_GET[“ptime2”]
例如某PHP文件:
<?php
if(isset($_GET["ptime1"])&&strlen($_GET["ptime1"])>0)
{
$time1=$_GET["ptime1"];
if(isset($_GET["ptime2"])&&strlen($_GET["ptime2"])>0)
{
$time2=$_GET["ptime2"];
$sql="SELECT * FROM `picture` WHERE ptime>='$time1'and ptime<='$time2' order by ptime desc";
}
else
{
$sql="SELECT * FROM `picture` WHERE ptime>='$time1' order by ptime desc";
}
}
else
{
if(isset($_GET["ptime2"])&&strlen($_GET["ptime2"])>0)
{
$time2=$_GET["ptime2"];
$sql="SELECT * FROM `picture` WHERE ptime<='$time2' order by ptime desc";
}
else{
$sql='select * from picture order by ptime desc';
}
}
?>