gpt4 book ai didi

javascript - 刷新后隐藏内容

转载 作者:行者123 更新时间:2023-11-28 04:44:42 27 4
gpt4 key购买 nike

我有三个下拉列表和很少的文本输入,第一个下拉列表用于隐藏一些不需要显示的输入,第二个下拉列表用于重新加载页面并使第三个下拉列表获取信息来自数据库基于第二个下拉菜单中的选项。现在,当我单击第二个下拉菜单时,我面临一个问题,页面重新加载,下拉菜单 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>";

最佳答案

您可以使用 window.name 来存储重新加载后仍然存在的标志。

没有链接,对不起,但您可以使用它代替本地存储或 cookie,以简单地实现逻辑以在页面重新加载后隐藏您想要的内容。 es:

if (window.name === "hide") {
element.style.display = "none";
}

关于javascript - 刷新后隐藏内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43485159/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com