首页 新闻 会员 周边

JS的实现

0
悬赏园豆:10 [已关闭问题]
Code

请问用JS怎么实现当选择下列表中“优惠信息”时优惠时间才显示出来?选择其他两个则隐藏优惠时间?

LoveO(∩_∩)O的主页 LoveO(∩_∩)O | 初学一级 | 园豆:55
提问于:2009-08-03 17:59
< >
分享
其他回答(2)
0
Code
$(function(){
$(
'#<%=ddlType.ClientID%>').change(function(){
if($(this).val()=='2')
$(
'#<%=panel1.ClientID%>').show();
    else
    $('#<%=panel1.ClientID%>').hide();
});
})

 

偷懒下

jquery的实现方式

rad | 园豆:28 (初学一级) | 2009-08-03 19:14
0

<script type="text/javascript">
function change(obj){
 if(obj.value=="3"){
  document.getElementById("Panel1").style.display="block";
 }else{
  document.getElementById("Panel1").style.display="none"; 
 }
}
</script>
然后给你的DropDownList加一个onchange="change(this)";

西越泽 | 园豆:10775 (专家六级) | 2009-08-04 11:51
我加了 可是onchange事件没触发到
支持(0) 反对(0) LoveO(∩_∩)O | 园豆:55 (初学一级) | 2009-08-04 13:43
可以进去了 可是document.getElementById("Panel1").style.display="block"; 这一句JS出错,说“缺少对象”
支持(0) 反对(0) LoveO(∩_∩)O | 园豆:55 (初学一级) | 2009-08-04 14:17
@LoveO(∩_∩)O: lz这完全可以用div,设置样式style="display:none" 然后在js里 <script type="text/javascript"> window.onload = function() { var obj=document.getElementById("ddlType"); obj.onchange = function() { if (obj.value == 3) { document.getElementById("Time").style.display = ""; } else { document.getElementById("Time").style.display = "none"; } } } </script>
@LoveO(∩_∩)O: div的ID为Time
0

    <script type="text/javascript">
function change(obj){
var aa=obj.options[obj.selectedIndex].value;

 if(aa=="3"){
  document.getElementById("Panel1").style.display="block";
 }else{
  document.getElementById("Panel1").style.display="none";
 }
}
    </script>

把你dropdownlist中的AutoPostBack去掉,把Panel 中的 Visible="false" 改成 style="display:none;"

就可以了

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="aa.aspx.cs" Inherits="text2_aa" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <script type="text/javascript">
function change(obj){
var aa=obj.options[obj.selectedIndex].value;

 if(aa=="3"){
  document.getElementById("Panel1").style.display="block";
 }else{
  document.getElementById("Panel1").style.display="none";
 }
}
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="ddlType" runat="server" size="1" onclick="change(this)" OnSelectedIndexChanged="ddlType_SelectedIndexChanged"
                >
                <asp:ListItem Value="0" Selected="True">请选择</asp:ListItem>
                <asp:ListItem Value="1">公告</asp:ListItem>
                <asp:ListItem Value="2">动态</asp:ListItem>
                <asp:ListItem Value="3">优惠信息</asp:ListItem>
            </asp:DropDownList>
            <asp:Panel ID="Panel1" runat="server" style="display:none;" >
 
                <tr>
                    <td class="style1">
                        优惠时间
                    </td>
                    <td>
                        <asp:TextBox ID="txtStarttime" runat="server" size="10" CssClass="Wdate" onFocus="new WdatePicker(this,'%Y-%M-%D',true,'default')"></asp:TextBox>
                        &nbsp;——
                        <asp:TextBox ID="txtEndttime" runat="server" size="10" CssClass="Wdate" onFocus="new WdatePicker(this,'%Y-%M-%D',true,'default')"></asp:TextBox>
                        <asp:Label ID="Label2" runat="server" Text="*" ForeColor="#FF3300"></asp:Label>
                    </td>
                </tr>
            </asp:Panel>
        </div>
    </form>
</body>
</html>

江峰 | 园豆:178 (初学一级) | 2009-08-04 18:00
恩 可以了 谢谢你
支持(0) 反对(0) LoveO(∩_∩)O | 园豆:55 (初学一级) | 2009-08-06 13:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册