为什么ASP.net RadioButtonList onchange客户端事件不触发? [英] Why doesn't ASP.net RadioButtonList onchange client side event trigger?
问题描述
我有asp.net项目,在那里我有一个母版页,我包括这一行,以引用JS文件
< script type =text / javascriptsrc =Scripts / HideDIV.js>< / script>
在JS文件中我有这个函数:
function hideDiv(){
document.getElementById('div1')。style.display ='none';
document.getElementById('div2')。style.display ='none';
$ b $ if(document.getElementById('RadioButtonTipoUser_0')!= null){
if(document.getElementById('RadioButtonTipoUser_0')。checked){
document.getElementById(' div1')。style.display ='block'; (document.getElementById('RadioButtonTipoUser_1')!= null){
if(document.getElementById('RadioButtonTipoUser_1')。checked)
if {
document.getElementById('div2')。style.display ='block';
$ / code>
基本上我需要在这个RadioButtonList上调用Js的一个函数hideDiv(),当选择一个Button时,一个div隐藏传递给visible。
这段代码在内容。
< div>
< asp:RadioButtonList ID =RadioButtonTipoUserrunat =serverRepeatDirection =Horizontalonchange =hideDiv()>
< asp:ListItem Selected =trueValue =1> Dome< / asp:ListItem>
< asp:ListItem Value =2> Emp< / asp:ListItem>
< asp:ListItem Value =3> Vet< / asp:ListItem>
< / asp:RadioButtonList>
< / div>
< div id =div1style =display:none>
< a> Charls< / a>
< / div>
< div id =div2style =display:none>< a> Maris< / a>< / div>
< / div>
我做了一个调试,错误信息是
ReferenceError:hideDiv未定义
我如何使onchange =hideDiv() 调用HideDiv()函数?
Bests
使用jquery完成您的任务
HTML
< DIV>
< asp:RadioButtonList ID =RadioButtonTipoUserrunat =serverRepeatDirection =Horizontal>
< asp:ListItem Selected =trueValue =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
< $($#$)$($#$)$($#$)$($# ('(this).is(':checked(');
$('#RadioButtonTipoUser_1')。on('change',function(){
if ')){
$('#div1')。show();
$('#div2')。hide();
}
}); $ b ($(this).is(':checked'))$ b $('#RadioButtonTipoUser_2')on('change',function(){
alert(ok1);
{
$('#div1')。hide();
$('#div2')。show();
}
});
} );
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>
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';
}
}
}
Basically i need on this RadioButtonList, call a function on Js "hideDiv()", when a select the one Button, one div hide pass to visible.
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
how i make tho the onchange="hideDiv()" call the HideDiv() function?
Bests
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屋!