RadioButton和RadioButtonGroup按钮的实现

本文通过一个简单的Flex应用实例介绍了如何使用RadioButton组件来让用户选择正确的答案,并展示了两种不同的实现方式:直接使用RadioButton和利用RadioButtonGroup进行管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" label="Radio" fontSize="12">
    
<!-- 用RadioButton实现   -->
    
<mx:RadioButton x="61" y="36" label="2001" id="item1" groupName="flex"/>
    
<mx:RadioButton x="155" y="36" label="2002" id="item2" groupName="flex"/>
    
<mx:RadioButton x="229" y="36" label="2003" id="item3" groupName="flex"/>
    
<mx:RadioButton x="303" y="36" label="2004" id="item4" groupName="flex"/>
    
<mx:RadioButton x="395" y="36" label="2005" id="item5" groupName="flex"/>
    
<mx:Label x="10" y="10" text="flex是哪一年发布的" width="131"/>
    
<mx:Label x="10" y="111" width="131" id="answer_txt"/>
    
<mx:Button x="10" y="61" label="提交" id="sub" click="answer_txt.text=(item2.selected?'正确':'错误')"/>
    
    
<!-- 用RadioButtonGroup实现   -->
    
<mx:Label x="10" y="139" text="我最想干的事是什么" id="lbl1"/>
    
<mx:RadioButtonGroup id="my1"/>
    
<mx:RadioButton x="61" y="167" label="打架" groupName="my1" id="item21"/>
    
<mx:RadioButton x="143" y="167" label="学习" groupName="my1" id="item22"/>
    
<mx:RadioButton x="209" y="167" label="听歌" groupName="my1" id="item23"/>
    
<mx:RadioButton x="273" y="167" label="游戏" groupName="my1" id="item24"/>
    
<mx:RadioButton x="339" y="167" label="看书" groupName="my1" id="item25"/>
    
<!-- 每个RadioButton的groupName属性必须和RadioButtonGroup的id同名,否则两者就会无法联系起来  -->
    
<mx:Label x="10" y="223" id="wo"/>
    
<mx:Button x="10" y="193" label="提交" click="wo.text=(item22.selected?'正确':'错误')"/>
</mx:Application>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值