根据显示的DropDownList隐藏事业部|显示 [英] Show|Hide Div depending on show DropDownList

查看:177
本文介绍了根据显示的DropDownList隐藏事业部|显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这东西太简单,但我如何显示在特定的ListItem DIV?

i know this thing is too simple but how i show div on specific ListItem ?

我的code是:

<asp:DropDownList ID="dropYesNo" runat="server">
    <asp:ListItem Text="Choose..." Value="-1"></asp:ListItem>
    <asp:ListItem Text="Yes" Value="1"></asp:ListItem>
    <asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:DropDownList>

后来我有一个div:

later on i have a div:

<div id="optional">
    <p>Please Enter Your Reason</p></br>
    <asp:TextBox ID="_refuse" runat="server" TextMode="MultiLine" />
    </br>
</div>

这DIV + CSS默认是隐藏的。
我想,当用户选择否的下拉,股利将出现。
我知道这是通常用JavaScript做的,但我不知道如何做到这一点。

this div CSS is hidden by default. i want that when the user chooses "No" on the drop down,the div will appear. i know it's usually done with JavaScript, but i didn't understand how to do it.

感谢您。

P.S。

我有另一个小相关的问题,
如果我在SQL有一个表分贝让调用它的用户,它有姓名,身份证列。
我如何加载整个列砸下来,所以如果用户选择一个名字就是它的ID。

i have another little related question, if i have a table in my SQL db lets call it users, and it has name , id columns. how do i load the entire columns to drop down so if the user chooses a name the is it's id.

推荐答案

使用jQuery的隐藏和股利的表现是pretty直截了当:

Using JQuery the hiding and showing of the Div is pretty straight forward:

$(function() {
  $("#dropYesNo").change(function() {
    ToggleDropdown();
  });
  ToggleDropdown(); // Done to ensure correct hiding/showing on page reloads due to validation errors
});

function ToggleDropdown() {
  if ($("#dropYesNo").val() == "No") {
    $("#optional").show();
  } else {
    $("#optional").hide();
  }
}; 

数据库方面真的取决于你正在使用和将正常完成服务器端的平台。你已经知道如何分配的文本和值属性,文本=名称,值= ID。

The database aspect really depends on the platform you are using and would be done server side normally. You already know how to assign the Text and the Value attributes, Text = Name, Value = ID.

这篇关于根据显示的DropDownList隐藏事业部|显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆