我有三个下拉列表和几个文本输入,第一个下拉用于隐藏一些输入,不需要显示,第二个下拉用于重新加载页面,并使第三个下拉取信息从数据库基于第二个下拉选项。现在我遇到一个问题,当我点击第二个下拉菜单,页面重新加载,输入隐藏在下拉列表1再次显示....
重新加载后获取值的代码:
<?php
@$utm=$_GET['utm']; // Use this line or below line if register_global is off
if(strlen($utm) > 0 and !is_numeric($utm))
{ // to check if $utm is numeric data or not.
echo "Data Error";
exit;
}
@$gpotp=$_GET['gpotp'];
if(strlen($gpotp) > 0 and !is_numeric($gpotp))
{
echo "Data Error";
exit;
}
?>
javascript隐藏内容(通过下拉菜单调用1):
<script>
function jsFunction(value)
{
var p = document.getElementById('ps');
var r = document.getElementById('rps');
var u = document.getElementById('upoint');
var m = document.getElementById('umng');
var t = document.getElementById('tmpass');
if ((value) == '1')
{
p.style.display = '';
r.style.display = '';
u.style.display = 'none';
m.style.display = 'none';
t.style.display = 'none';
}
else if ((value) == '2')
{
p.style.display = 'none';
r.style.display = 'none';
u.style.display = '';
m.style.display = 'none';
t.style.display = '';
}
if ((value) == '3')
{
p.style.display = 'none';
r.style.display = 'none';
u.style.display = '';
m.style.display = '';
t.style.display = '';
}
}
</script>
重新加载页面的代码(下拉2时调用):
function reload(form)
{
var val=form.utm.options[form.utm.options.selectedIndex].value;
var va2=form.gpotp.options[form.gpotp.options.selectedIndex].value;
self.location='CrtGroup.php?utm=' + val +'&gpotp=' + va2 ;
}
下拉1:
<select name='gpotp' class='form-control' onmousedown=\"this.value='';\" onchange=\"jsFunction(this.value);\">
<option disabled selected value> -- select an option -- </option>";
if($stmt = $conn->query("$query3"))
{
while ($row2 = $stmt->fetch_assoc())
{
if($row2['Group_ID']==@$gpotp){echo "<option selected value='$row2[Group_ID]'>$row2[Group_Cat]</option>";}
else{echo "<option value='$row2[Group_ID]'>$row2[Group_Cat]</option>";}
}
}else
{
echo $conn->error;
}
echo"</select>
下拉2:
echo"<select class='form-control' onchange=\"reload(this.form)\" name='utm' onmousedown=\"this.value='';\">";
echo"<option disabled selected value> -- select an option -- </option>";
if($stmt = $conn->query("$query2"))
{
while ($row2 = $stmt->fetch_assoc())
{
if($row2['Group_ID']==@$utm){echo "<option selected value='$row2[Group_ID]'>$row2[Tm_GroupID]</option>";}
else{echo "<option value='$row2[Group_ID]'>$row2[Tm_GroupID]</option>";}
}
}else
{
echo $conn->error;
}
echo"</select>";
下拉3:
echo"<select class='form-control' name='umn' >";
echo"<option disabled selected value> -- select an option -- </option>";
if(isset($utm) and strlen($utm) > 0){
if($stmt = $conn->prepare("SELECT DISTINCT Mng_GroupID,Group_ID,Tm_GroupID FROM mnggroup where Tm_GroupID=? order by Mng_GroupID"))
{
$stmt->bind_param('i',$utm);
$stmt->execute();
$result = $stmt->get_result();
while ($row1 = $result->fetch_assoc()) {
echo "<option value='$row1[Group_ID]'>$row1[Mng_GroupID]</option>";
}
}else{
echo $conn->error;
}
/////////
}else{
///////
$query="SELECT DISTINCT Mng_GroupID,Group_ID,Tm_GroupID FROM mnggroup order by Mng_GroupID";
if($stmt = $conn->query("$query")){
while ($row1 = $stmt->fetch_assoc()) {
echo "<option value='$row1[Group_ID]'>$row1[Mng_GroupID]</option>";
}
}else{
echo $conn->error;
}
}
echo"</select>";
答案 0 :(得分:0)
您可以使用window.name存储重新加载后仍然存在的标志。
没有链接,对不起,但您可以使用它而不是本地存储或cookie来简单地实现逻辑以在页面重新加载后隐藏您想要的内容。 ES:
if (window.name === "hide") {
element.style.display = "none";
}