我正在尝试创建一组下拉菜单以创建“搜索”。应该隐藏每个下拉列表,直到选择了上一个下拉列表。上一个选择的值与下一个下拉列表中的值无关。如果上一个下拉列表仍然是默认值,则只应隐藏它们。有没有办法让这成为可能?我已经能够隐藏第二个下拉列表,但是从第三个下拉列表开始,我无法使它们动态显示。
我希望隐藏“年份”之后的所有下拉列表,并在每次下拉列表后显示下一个。
这是我目前的代码:
<form name="ftpquery" method="post" action="sendFTP.php">
<select name="year">
<option value="">Year</option>
<?php for($i = 1992; $i < 2016; $i++) { ?>
<option value = "<?php echo $i; ?>"><?php echo $i; ?></option>;
<?php } ?>
</select>
<select name = "julian">
<option value = "">Julian</option>
<?php
for($i = 1; $i < 366; $i++){
?>
<option value = "<?php echo $i ?>"><?php echo $i ?></option>;
<?php } ?>
</select>
<select name = "station">
<option value = "">Station</option>
<?php
while ($row = mysqli_fetch_array($response)){
?>
<option value = "<?php echo $row['Station'] ?>"><?php echo $row['Station'] ?></option>;
<?php } ?>
</select>
<select name = "month">
<option value = "">Month</option>
<?php
for($i = 1; $i < 13; $i++){
?>
<option value = "<?php echo $i ?>"><?php echo $i ?></option>;
<?php } ?>
</select>
<select name = "day">
<option value = "">Day</option>
<?php
for($i = 1; $i <= 31; $i++){
?>
<option value = "<?php echo $i ?>"><?php echo $i ?></option>;
<?php } ?>
</select>
<select name = "hour">
<option value = "">Hour</option>
<?php
for($i = 0; $i <= 23; $i++){
?>
<option value = "<?php echo $i ?>"><?php echo $i ?></option>;
<?php } ?>
</select>
<select name = "min">
<option value = "">Min</option>
<option value = "00"><?php echo "00" ?></option>;
<option value = "15"><?php echo "15" ?></option>;
<option value = "30"><?php echo "30" ?></option>;
<option value = "45"><?php echo "45" ?></option>;
</select>
<select name = "version">
<option value = "">Version</option>
<option value = "a"><?php echo "a" ?></option>;
<option value = "b"><?php echo "b" ?></option>;
</select>
<p>
<input type="submit" value="Submit">
</p>
</form>
</body>
有没有办法让这成为可能?
感谢您的时间和帮助!
答案 0 :(得分:1)
我在jQuery中运行这样的东西:
<style>
select.date-select {
display: none;
}
</style>
<script type="text/javascript">
function selectShowHide()
{
// Loop through all the .date-select selects
$("select.date-select").each(function() {
if ($(this).val() == 0) {
// If it has no value hide it
$(this).next("select.date-select").hide();
} else {
// If it does show it
$(this).next("select.date-select").show();
}
});
}
$(function(){
// On load activate the show hide
selectShowHide();
// Show the first one
$("select.date-select").first().show();
// On change of select work out what to hide
$("select.date-select").change(function(){
selectShowHide();
});
});
</script>
您需要为所有选择提供一个日期选择类:
<select class="date-select">
</select>