javascript - JQuery.css("display") = "block" not working - Stack Overflow

I wanted to show and hide my TextBox based on value selected in RadiobuttonList. I wrote the following

I wanted to show and hide my TextBox based on value selected in RadiobuttonList. I wrote the following code for that

$("#<%= rbtnIsPFEnabled.ClientID %>").click(function () {
                pfno = $("#<%= txtPFNo.ClientID %>");
                if ($("#<%= rbtnIsPFEnabled.ClientID %> input:checked").val() == "Yes") {
                    pfno.css("dispay") = "block";
                }
                else
                    pfno.css("dispay") = "none";
            });

Though I had achieved my task by using JQuery.show() and JQuery.hide() but was not satisfied as I wanted to know why first approach failed. Second is I used $("#<%= rbtnIsPFEnabled.ClientID %>") in above code, can I reduce it to one by using something else second time like this or anything else?

I tried $(this+" input:checked").val() and $(this.toString()+" input:checked").val() but it did not work, so I had to repeat it.

I wanted to show and hide my TextBox based on value selected in RadiobuttonList. I wrote the following code for that

$("#<%= rbtnIsPFEnabled.ClientID %>").click(function () {
                pfno = $("#<%= txtPFNo.ClientID %>");
                if ($("#<%= rbtnIsPFEnabled.ClientID %> input:checked").val() == "Yes") {
                    pfno.css("dispay") = "block";
                }
                else
                    pfno.css("dispay") = "none";
            });

Though I had achieved my task by using JQuery.show() and JQuery.hide() but was not satisfied as I wanted to know why first approach failed. Second is I used $("#<%= rbtnIsPFEnabled.ClientID %>") in above code, can I reduce it to one by using something else second time like this or anything else?

I tried $(this+" input:checked").val() and $(this.toString()+" input:checked").val() but it did not work, so I had to repeat it.

Share edited Dec 18, 2014 at 5:30 Imad asked Dec 18, 2014 at 5:25 ImadImad 7,49014 gold badges62 silver badges124 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 4
$("#id").css("display", "none");
$("#id").css("display", "block");

if Your pfno contains your ID

then this should work

$(pfno).css("display", "none");
$(pfno).css("display", "block");

You Should Use FireBug For Debugging

EDIT:

<script type="text/javascript">
    function fun(obj) {

        if ($("#<%= rbtnIsPFEnabled.ClientID %> input:checked").val()=='Yes') {
            $("#<%= txtPFNo.ClientID %>").css("display", "block");
        }
        else {
            $("#<%= txtPFNo.ClientID %>").css("display", "none");
        }
    }


</script>  

<asp:RadioButtonList   ID="rbtnIsPFEnabled"     runat="server" >
    <asp:ListItem Text="Yes" Value="Yes" onchange="fun(this);"> </asp:ListItem>
    <asp:ListItem Text="No" Value="No" onchange="fun(this);"> </asp:ListItem>
    </asp:RadioButtonList>

    <asp:TextBox runat="server" ID="txtPFNo"/>

You can resolve this issue in multiple way using jQuery. e.g.

$(pfno).css("display", "none"); //used when you are defining single css property or in chaining method
$(pfno).css({"display":"none"}); // used when you are defining multiple CSS property           
$(pfno).hide(); //show/hide function also perform display block/none functionality which is mostly used in script

ok first of all this is not correct :

     pfno.css("dispay") = "block";

above will never work

pfno.css({ 'display' : 'block' }); is how you set a css property ,

pfno.css( 'display' , 'block' ); is another way to set a css property , so that measn yuo are doing something else wrong.. you need to set an alert or write to the console to confirm that your if statement and your click handler are working

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745053232a4608513.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信