我在表单中选择了数据库中不同类型的设备(devices.insert.php
):
Type:<select name="type" form="form_select" onchange="showDiv(this)">
<?php
$sql = "SELECT *
FROM Property
WHERE PRP_PRP_TYP_Id = 1";
$result = sqlsrv_query($con, $sql);
echo "<option disabled selected value> -- select an option -- </option>";
while ($row = sqlsrv_fetch_array($result)){
echo "<option value='".$row['PRP_Id']."'>".$row['PRP_Value']."</option>";
}
?>
</select><br>
<script type="text/javascript">
function showDiv(elem){
if(elem.value == 3 || elem.value == 24 || elem.value == 25){
document.getElementById('sc_div').style.display = "block";
}
else{
document.getElementById('sc_div').style.display = "none";
}
}
</script>
当我选择一个具有正确id
的项目时,div
元素将显示为具有更多选项。
<div id="sc_div" style="display:none">
...
<a href="sim_cards_insert.php">Register new SIM</a><br>
</div>
在sim_cards_insert.php
中,我有一个带有submit和cancel的表单,当我按下返回(到devices_insert.php
)时,div sc_div
不再可见,但我之前填写的数据在同一位置。
<button type="button" class="log-btn" onClick="history.go(-1)">Cancel</button>
如何通过不同的窗口再次看到它?
听起来浏览器正在将DOM恢复到其初始状态,即隐藏sc_div
。
也许您可以检查devices_insert.php
页面加载的先前URL。
<script type="text/javascript">
function showDiv(elem){
//example
var filename = document.referrer.split('/').pop();
if(filename === 'sim_card_insert.php'){
document.getElementById('sc_div').style.display = "block";
}
//...rest of function
</script>