加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flashbuilder4 单选 RadioButton RadioButtonGroup

发布时间:2020-12-15 18:30:01 所属栏目:百科 来源:网络整理
导读:转载:?http://www.fbair.net/bbs/read.php?tid=156 单选 RadioButton 和 RadioButtonGroup 控件介绍??? RadioButtonGroup 相当于Html里面的input type="radio" name="XXX"的Name属性, 而RadioButton 相当于input type="radio"的每个值 官方文档 http://hel

转载:?http://www.fbair.net/bbs/read.php?tid=156


单选 RadioButton 和 RadioButtonGroup 控件介绍??? RadioButtonGroup 相当于Html里面的<input type="radio" name="XXX"的Name属性, 而RadioButton 相当于<input type="radio"的每个值

官方文档
http://help.adobe.com/zh_CN/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7d8b.html
http://help.adobe.com/zh_CN/AS3LCR/Flex_4.0/mx/controls/RadioButton.html
http://help.adobe.com/zh_CN/AS3LCR/Flex_4.0/spark/components/RadioButton.html
单选框 RadioButton? 组件 有2种 分别包含在??MX and Spark 组件里面, 官方建议 使用spark组件里面的
RadioButtonGroup 由于是非可见元素 需要放到 <fx:Declarations> 标签中
[pre]RadioButton? 的 click事件??请查看如下例子中的 click="handleAmEx(event)",click="handleMC(event),click="handleVisa(event)

复制代码
  1. <?xml version="1.0"?>
  2. <!-- controlsbuttonRBEvent.mxml -->
  3. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  4. ????xmlns:s="library://ns.adobe.com/flex/spark"
  5. ????xmlns:mx="library://ns.adobe.com/flex/mx">
  6. ????<fx:Script>
  7. ????????<![CDATA[??
  8. ????????????import flash.events.Event;
  9. ????????????private function handleAmEx(event:Event):void {
  10. ????????????????// Handle event.
  11. ????????????????myTA.text="Got Amex";
  12. ????????????}
  13. ????????????private function handleMC(event:Event):void {
  14. ????????????????myTA.text="Got MasterCard";
  15. ????????????private function handleVisa(event:Event):void {
  16. ????????????????myTA.text="Got Visa";
  17. ????????]]>
  18. ????</fx:Script>
  19. ????
  20. ????<s:VGroup>
  21. ????????<s:RadioButton groupName="cardtype"
  22. ????????????id="americanExpress"
  23. ????????????label="American Express"
  24. ????????????width="150"
  25. ????????????click="handleAmEx(event);"/>
  26. ????????????id="masterCard"
  27. ????????????label="MasterCard"
  28. ????????????click="handleMC(event);"/>
  29. ????????????id="visa"
  30. ????????????label="Visa"
  31. ????????????click="handleVisa(event);"/>
  32. ????????<s:TextArea id="myTA"/>
  33. ????</s:VGroup>
  34. </s:Application>


创建一组 单选框 ?由于 所有的 RadioButton 都属于 cardtype 组 所以可以直接 用 cardtype.selectedValue 显示选中的值
复制代码
<!-- controlsbuttonRBGroupSimple.mxml -->
  • ????????????import mx.events.ItemClickEvent;
  • ????????????private function handleCard(event:ItemClickEvent):void {
  • ????????????????//Print the value of the selected RadioButton in the Text Area
  • ????????????????var cardValue:Object = cardtype.selectedValue;
  • ????????????????myTA.text="You selected " + cardValue;
  • ????<fx:Declarations>
  • ????????<s:RadioButtonGroup id="cardtype"
  • ????????????itemClick="handleCard(event);"/>
  • ????</fx:Declarations>
  • ????????<s:RadioButton group="{cardtype}"
  • ????????????width="150"/>

  • 通过设置的 “click点击”? ItemClickEvent ?监听器? private function? handleCard (event:ItemClickEvent):void? 来监听单选选择时的 click 事件
    复制代码
  • <!-- controlsbuttonRBGroupEvent.mxml -->
  • ????????????import mx.controls.Alert;
  • ????????????import mx.events.ItemClickEvent;//需要导入该包
  • ????????????????if (event.currentTarget.selectedValue == "AmEx") {
  • ????????????????????Alert.show("You selected American Express.");
  • ????????????????} else if (event.currentTarget.selectedValue == "MC") {
  • ????????????????????????Alert.show("You selected MasterCard.");
  • ????????????????} else {
  • ????????????????????Alert.show("You selected Visa.");
  • ????????????????}
  • ????????????value="AmEx"
  • ????????????value="MC"
  • ????????????value="Visa"


  • 通过键盘操作 单选
  • (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读