Javascript function behaviour

后端 未结 2 651
谎友^
谎友^ 2021-01-25 02:06

I have a problem with javascript. In my code there is a radio button, on click it should call the UcSelect() function. I tried the code below but it didn\'t work. T

相关标签:
2条回答
  • 2021-01-25 02:49

    script elements can have a src attribute or content, but not both. If they have both, the content is ignored (the content is considered "script documentation," not code).

    As you are using ASP.NET and rbtTipo is a server control you need to use Control.ClientID.

    <%= rbtTipo.ClientID %> will Gets the control ID for HTML markup that is generated by ASP.NET.

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
    </script>
    <script>
        function UcSelect() {
            var value = $("#<%= rbtTipo.ClientID %> :checked").val();
            if (value == 'E') {
                alert("aaaaaaaaaaaaa");
            }
            if (value == 'G') {
                alert("bbbbbbbbbbbbbbbbbb");
            }
            return true;
        }
    </script>
    
    0 讨论(0)
  • 2021-01-25 02:56

    You need to update your code. You have to close the script tag properly

    Add there is a redundant code of checking value E. You should remove that code or update it to check for G. For your reference, I have updated the code below.

     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
     <script type="text/javascript">
    
        function UcSelect() {
            alert('hello1');
            if ($("#rbtTipo :checked").val() == 'E') {
                alert("aaaaaaaaaaaaa");
            }
            if ($("#rbtTipo :checked").val() == 'G') {
                alert("bbbbbbbbbbbbbbbbbb");
            }
            return true;
        }
    
    </script>
    
    0 讨论(0)
提交回复
热议问题