为什么ASP.net RadioButtonList onchange客户端事件无法触发? [英] Why doesn't ASP.net RadioButtonList onchange client side event trigger?

查看:88
本文介绍了为什么ASP.net RadioButtonList onchange客户端事件无法触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net项目,在其中我有一个母版页(包括该行)以引用JS文件

i have asp.net project, where i have a master-page on I include this line, to reference of the JS file

<script type="text/javascript" src="Scripts/HideDIV.js"></script>

在JS文件中,我具有以下功能:

In the JS file i have this function:

function hideDiv() {
    document.getElementById('div1').style.display = 'none';
    document.getElementById('div2').style.display = 'none';

    if (document.getElementById('RadioButtonTipoUser_0') != null) {
        if (document.getElementById('RadioButtonTipoUser_0').checked) {
            document.getElementById('div1').style.display = 'block';
        }
    }

    if (document.getElementById('RadioButtonTipoUser_1') != null) {
        if (document.getElementById('RadioButtonTipoUser_1').checked) {

            document.getElementById('div2').style.display = 'block';

        }
    }
}

基本上我需要在此单选按钮列表,呼叫上的jshideDiv()",一个函数时,选择所述一个按钮,一个DIV隐藏通到可见.

Basically i need on this RadioButtonList, call a function on Js "hideDiv()", when a select the one Button, one div hide pass to visible.

此代码已包含内容.

<div>
        <asp:RadioButtonList ID="RadioButtonTipoUser" runat="server" RepeatDirection="Horizontal" onchange="hideDiv()">

            <asp:ListItem Selected="true" Value="1">Dome</asp:ListItem>
            <asp:ListItem Value="2">Emp</asp:ListItem>
            <asp:ListItem Value="3">Vet</asp:ListItem>
        </asp:RadioButtonList>


    </div>

    <div id="div1" style="display:none">
        <a>Charls</a>
    </div>
    <div id="div2" style="display:none"><a>Maris</a></div>
</div>

我进行调试,错误消息为

I make a debug and the error msg is

ReferenceError:未定义hideDiv

ReferenceError: hideDiv is not defined

我如何让onchange ="hideDiv()"调用HideDiv()函数?

how i make tho the onchange="hideDiv()" call the HideDiv() function?

最佳

推荐答案

您使用jquery完成任务

you use jquery for achieving your task

HTML

<div>
        <asp:RadioButtonList ID="RadioButtonTipoUser" runat="server" RepeatDirection="Horizontal">

            <asp:ListItem Selected="true" Value="1">Dome</asp:ListItem>
            <asp:ListItem Value="2">Emp</asp:ListItem>
            <asp:ListItem Value="3">Vet</asp:ListItem>
        </asp:RadioButtonList>


    </div>

    <div id="div1" >
        <a>Charls</a>
    </div>
    <div id="div2" ><a>Maris</a></div>

JQUERY

 $(document).ready(function () {

        $('#div1').hide();
        $('#div2').hide();
        $('#RadioButtonTipoUser_1').on('change', function () {

            if ($(this).is(':checked')) {
                $('#div1').show();
                $('#div2').hide();
            }
        });
        $('#RadioButtonTipoUser_2').on('change', function () {
            alert("ok1");
            if ($(this).is(':checked')) {
                $('#div1').hide();
                $('#div2').show();
            }
        });
    });

这篇关于为什么ASP.net RadioButtonList onchange客户端事件无法触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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