隐藏下拉列表选择值发生变化时,一个div [英] Hiding a div when dropdown selected value changes

查看:595
本文介绍了隐藏下拉列表选择值发生变化时,一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,当选择的值改变我想隐藏一个div。 (还有另外一个工具,使得DIV可见)。

I have a dropdown list that when the selected value changes I want to hide a div. (There is another control that makes the div visible).

目前,我有以下的,但是当我更改下拉选定值股利不躲了起来。

I currently have the following but the div is not hiding when I change the selected value in the dropdown.

<script type="text/javascript">
$(document).ready(function () {

    $('#MyDd').change(function () {
        $('#buttonDiv').hide();            
    });
});

</script>

<asp:DropDownList ID="MyDd" runat="server" /> 
<div id="buttonDiv" class="buttonContainer">
    <asp:Button ID="myButton" runat="server" /> 
</div>

任何想法为什么会不工作?

Any ideas why this wouldn't be working?

在此先感谢您的帮助。

推荐答案

在页面呈现的Asp.net服务器端控件的ID变化。因此,MyDd将不再是降downlist的ID。你必须注册背后通过code JavaScript的变量。尝试保存下拉的客户端ID在一个局部变量并注册脚本。

The Id of the server side controls of Asp.net changes when the page is rendered. So "MyDd" will no longer be the Id of the drop downlist. You have to register javascript variables through code behind. Try to save the client id of the dropdown in a local variable and register the script.

您可以指定一个类的下拉,然后分配使用类元素的事件。

You can specify a class for the dropdown and then assign an event for the element using the class.

<asp:DropDownList ID="DropDownList1" runat="server" class="cls">
   <asp:ListItem Text="One" Value="1" />
   <asp:ListItem Text="Two" Value="2" />
</asp:DropDownList>

<script type="text/javascript">
 $().ready(function () {
     $('.cls').change(function () {
         alert('hi');
     });
 });
 </script>

我用的jQuery这里工作的。

i used jquery here and this works.

这篇关于隐藏下拉列表选择值发生变化时,一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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