呼吁单选按钮列表的onchange Asp.net的JavaScript funcion [英] Call javascript funcion on RadioButtonList onchange Asp.net

查看:99
本文介绍了呼吁单选按钮列表的onchange Asp.net的JavaScript funcion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

        }
    }
}

基本上我需要在这个RadioButtonList的,呼吁的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.

这code是内容。

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

我做一个调试和错误msg是

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

这篇关于呼吁单选按钮列表的onchange Asp.net的JavaScript funcion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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