简体   繁体   English

为什么ASP.net RadioButtonList onchange客户端事件没有触发?

[英]Why doesn't ASP.net RadioButtonList onchange client side event trigger?

i have asp.net project, where i have a master-page on I include this line, to reference of the JS file 我有asp.net项目,我有一个主页面,我包括这一行,以参考JS文件

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

In the JS file i have this function: 在JS文件中我有这个功能:

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';

        }
    }
}

Basically i need on this RadioButtonList, call a function on Js "hideDiv()", when a select the one Button, one div hide pass to visible. 基本上我需要在这个RadioButtonList上,在Js“hideDiv()”上调用一个函数,当选择一个Button时,一个div隐藏传递给可见。

This code is in content. 此代码包含在内容中。

<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 is not defined ReferenceError:未定义hideDiv

how i make tho the onchange="hideDiv()" call the HideDiv() function? 我如何使onchange =“hideDiv()”调用HideDiv()函数?

Bests 贝斯茨

you use jquery for achieving your task 你使用jquery来完成你的任务

HTML 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 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();
            }
        });
    });

Our site was an intranet, and I had to turn off Display Intranet Sites in Compatibility View in Internet Explorer for onchange to work in RadioButtonList. 我们的站点是一个内部网,我不得不在Internet Explorer的兼容性视图中关闭显示Intranet站点,以便在ExchangeButtonList中工作。 It appears that ASP.NET actually adds a javascript event to the containing table that a RadioButtonList renders as, and IE in Compatibility View stops that working. 看起来ASP.NET实际上将一个javascript事件添加到RadioButtonList呈现的包含表中,并且兼容性视图中的IE停止了该工作。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM