单选按钮Onclick事件 [英] Radio Button Onclick event

查看:162
本文介绍了单选按钮Onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击事件时在单选按钮中调用函数背后的代码

I want call a code behind function in radio button on click event

<asp:RadioButtonList ID="grpLocation" runat="server" RepeatDirection="Horizontal"

OnDataBound="grpLocation_onDataBound">
</asp:RadioButtonList>







RadioButtonList rbl = (RadioButtonList)sender;
       foreach (ListItem li in rbl.Items)
       {
           li.Attributes.Add("onclick", "javascript:ShowExt('" + li.Value + "')");
       }







<script language=javascript type="text/javascript">
   function ShowExt(object)
   {
   alert("Value Clicked :" + object);
   }
   </script>



正在使用此代码,但我需要在脚本块内调用一个函数,请给出建议和示例代码.谢谢您



am using this code but i need to call a function inside the script block please give ur suggestion and sample code thank you

推荐答案

这里单击按钮的简单示例单选按钮事件:

Here''s a simple example on button click event of Radio Button :

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
<script language="javascript">
function choixPersonne(chaine)
{
var a = document.getElementById("rien");
var b= document.getElementById("option");

if (chaine == 'cacher1'){

a.style.display = "none";
b.style.display = "block";
}
else if (chaine == 'cacher2'){

a.style.display = "block";
b.style.display = "none";
}

}
</script>

</head>
<body>

<div data-role="page" data-theme="b">
<div data-role="header">
<h1>Quel vin boire, choisir, servir ?</h1>
</div> <!-- /header-->

<div data-role="content">
<div class="ui-body ui-body-a">
<form action="" name="recherche" id="recherche" method="post">
<fieldset data-role="controlgroup">
<input type="radio" name="personne" id="ouiCli" value="oui" onchange="choixPersonne('cacher1')" checked="checked" />
<label for="ouiCli" >plats/mets</label>
<input type="radio" name="personne" id="nonCli" value="non" onchange="choixPersonne('cacher2')" />
<label for="nonCli">vins</label>
<label for="query">Entrez votre plat ou votre vin</label>
<input type="text" name="query" size="37" value="" />

<!--Les champs à masquer:-->
<div id="rien" style="display:none"><fieldset class="Style7">
</fieldset></div>
<div id="option" style="display:none"><fieldset class="Style7">
<label style="display:inline"><br>Nos accords mets et vins fonctionnent uniquement avec les appellations (Exemple : Sauternes, Chinon etc..)</label>
</fieldset>
</div>
</fieldset>
<input type="submit" name="button" value="rechercher" />
</form>
</div>
</div><!-- /content-->
</div><!-- /page-->

</body>
</html>



您也可以尝试jQuery:



You can also try jQuery :


(" ).change(function(){ var selection =
("input[type='radio']").change(function () { var selection=


( this ).val(); alert(" + selection); });
(this).val(); alert("Radio button selection changed. Selected: "+selection); });


这篇关于单选按钮Onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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