我想在我的頁面上選擇2個選項之一時顯示div。這裏是選擇菜單:如果在jQuery中選擇了選項,則顯示div div
<select id="graph_select">
<option id="pilot_form">Pilot Hours</option>
<option id="client_form">Client Hours</option>
</select>
這裏是我的第一選擇第一個div:
<div id="pilot_graph_form" align="center" style="margin:0 auto; display:none;">
<form action="?page=reporter" method="POST" name="graph_form">
<p>From:</p>
<select name="start_date">
<cfloop query="date_worked_menu">
<option>#date_worked_menu.date_worked#</option>
</cfloop>
</select>
<br />
<br />
<p>To:</p>
<select name="end_date">
<cfloop query="date_worked_menu">
<option>#date_worked_menu.date_worked#</option>
</cfloop>
</select>
<br />
<input class="btn btn-success" type="Submit" name="submit_to_graph" value="Submit" id="submit_to_graph">
</form>
</div>
這裏是我的第二個選項股利:
<div id="client_graph_form" align="center" style="margin:0 auto; display:none;">
<form action="?page=reporter" method="POST" name="graph_form_clients">
<p>From:</p>
<select name="client">
<cfloop query="client_menu">
<option value="#client_menu.id#">#client_menu.name#</option>
</cfloop>
</select>
<input class="btn btn-success" type="Submit" name="submit_to_graph" value="Submit" id="submit_to_graph">
</form>
</div>
這裏是我的jQuery功能我目前爲止:
<script type="text/javascript">
$(function() {
$("#graph_select").change(function() {
if($("#pilot_form").is(":selected")) {
$("#pilot_graph_form").css({"display":"block"});
}
else {
$("#pilot_graph_form").css({"display":"none"});
}
if($("#client_form").is(":selected")) {
$("#client_graph_form").css({"display":"block"});
}
else {
$("#client_graph_form").css({"display":"none"});
}
});
});
</script>
那麼,什麼是你的問題是什麼呢? – Swordfish0321
聽onchange。 –
現在正確格式化。沒有必要爲此失眠 –