显示和隐藏表使用JQuery
问题描述:
我有这个功能可以显示或隐藏表显示和隐藏表使用JQuery
function show_ticket_type(){
if ($("#TicketType").val("select-type")){
$("#tow_way").hide()
$("#one_way").hide()
}
else if ($("#TicketType").val("one-way")){
$("#tow_way").hide()
$("#one_way").show()
}
else{
$("#tow_way").show()
$("#one_way").hide()
}
}
和表
<table width="100%" border="0" id="tow_way">
<tr>
<th width="120"> <div align="center"><strong>Airlines</strong></div></th>
<th width="100"> <div align="center"><strong>Type</strong></div></th>
<th width="100"> <div align="center"><strong>From</strong></div></th>
<th width="100"> <div align="center"><strong>To</strong></div></th>
<th width="80"> <div align="center"><strong>Departure</strong></div></th>
<th width="100"> <div align="center"><strong>Returning</strong></div></th>
</tr>
</tbale>
<table width="100%" border="0" id="one_way">
<tr>
<th width="120"> <div align="center"><strong>Airlines</strong></div></th>
<th width="100"> <div align="center"><strong>Type</strong></div></th>
<th width="100"> <div align="center"><strong>From</strong></div></th>
<th width="100"> <div align="center"><strong>To</strong></div></th>
<th width="80"> <div align="center"><strong>Departure</strong></div></th>
</tr>
</tbale>
这是选择类型时选择价值,我们必须呼叫功能隐藏或显示表格
<select id="TicketType" name="TicketType" onChange="show_ticket_type()">
<option value="select-type">-- Select --</option>
<option value="one-way">One Way</option>
<option value="tow-way">Return</option>
</select>
如果我选择单程我们必须隐藏表tow_way和显示表one_way当选择拖拉方式我们必须要隐藏表one_way和显示表tow_way否则,我们必须隐藏拖表
我的代码中的错误在哪里?
答
$('#TicketType').change(function(){
$("#two_way").toggle(this.value == "two-way")
$("#one_way").toggle(this.value == "one-way")
});
- 固定的类型 -
tow
=>two
,因为拖的方式听起来令人毛骨悚然...... :)
答
你在想什么,你在这里干嘛?
$("#TicketType").val("select-type")
您正试图设置该值而不是读取该值。
你应该做if($("#TicketType").val() === "select-type")
此外,你应该介意你的拼写:)
+0
谢谢@hop为您的解决方案 – 2013-03-06 20:37:49
什么错误信息你好吗? – Mortalus 2013-03-06 20:20:17
你的代码中有很多错别字,从'tow-way'到'tbale'。 – MattDiamant 2013-03-06 20:26:41