使用flex填充文本框

发布于 2024-09-29 14:14:42 字数 2591 浏览 3 评论 0原文

在下面的代码中。如果按下按钮“A”,则文本框应填充 A,如果按下按钮“B”,则应填充 B,依此类推。 这可以完成吗?如果有人能给我指出弹性示例将会很有帮助。谢谢..

                  s='A';
                for(i=0;i<button.length;i++)
                {
                        txtLogin.text+=s;
                        s++;
                }  

原始代码..

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

            <mx:Button label="A" click="clickhandler(event)"  x="1" />
            <mx:Button label="B" click="clickhandler(event)"  x="101" />
            <mx:Button label="C" click="clickhandler(event)"  x="201" />
            <mx:Button label="D" click="clickhandler(event)"  x="301" />
            <mx:Button label="E" click="clickhandler(event)"  x="401" />
            <mx:Button label="F" click="clickhandler(event)"  x="501" />
            <mx:Button label="G" click="clickhandler(event)"  x="601" />
            <mx:Button label="H" click="clickhandler(event)"  x="701" />
            <mx:Button label="I" click="clickhandler(event)"  x="801" />
            <mx:Button label="J" click="clickhandler(event)"  x="901" />
            <mx:Button label="K" click="clickhandler(event)"  x="1001" />



            <mx:Script>
                    <![CDATA[
                    import mx.controls.Button;
                    import mx.controls.Alert;

                    public function clickhandler(event:Event):void
                    {

                    var button:Button=event.target as Button;
                    var i:int;
                    var s:String;
                    s='A';
                    for(i=0;i<button.length;i++)
                    {
                            txtLogin.text+=s;
                            s++;
                    }       
            /*      if (button.label=='A')
                    {
                            txtLogin.text+="A";
                            //mx.controls.Alert.show("Button1");
                    }
                    if (button.label=="B")
                    {               
                            txtLogin.text+="B";
                            //mx.controls.Alert.show("Button2");
                    }                       */
                    }
                            ]]>      

            </mx:Script>
                    <mx:TextInput x="231" y="175" id="txtLogin"/>



            </mx:Application>

In the below code.If buttom 'A' is pressed the text box should be populated with A, and if button 'B' is pressed it should be populated with B and so on..
Can this be done.Also if any one could point me to flex examples would be much helpful.Thanks..

                  s='A';
                for(i=0;i<button.length;i++)
                {
                        txtLogin.text+=s;
                        s++;
                }  

Original code..

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

            <mx:Button label="A" click="clickhandler(event)"  x="1" />
            <mx:Button label="B" click="clickhandler(event)"  x="101" />
            <mx:Button label="C" click="clickhandler(event)"  x="201" />
            <mx:Button label="D" click="clickhandler(event)"  x="301" />
            <mx:Button label="E" click="clickhandler(event)"  x="401" />
            <mx:Button label="F" click="clickhandler(event)"  x="501" />
            <mx:Button label="G" click="clickhandler(event)"  x="601" />
            <mx:Button label="H" click="clickhandler(event)"  x="701" />
            <mx:Button label="I" click="clickhandler(event)"  x="801" />
            <mx:Button label="J" click="clickhandler(event)"  x="901" />
            <mx:Button label="K" click="clickhandler(event)"  x="1001" />



            <mx:Script>
                    <![CDATA[
                    import mx.controls.Button;
                    import mx.controls.Alert;

                    public function clickhandler(event:Event):void
                    {

                    var button:Button=event.target as Button;
                    var i:int;
                    var s:String;
                    s='A';
                    for(i=0;i<button.length;i++)
                    {
                            txtLogin.text+=s;
                            s++;
                    }       
            /*      if (button.label=='A')
                    {
                            txtLogin.text+="A";
                            //mx.controls.Alert.show("Button1");
                    }
                    if (button.label=="B")
                    {               
                            txtLogin.text+="B";
                            //mx.controls.Alert.show("Button2");
                    }                       */
                    }
                            ]]>      

            </mx:Script>
                    <mx:TextInput x="231" y="175" id="txtLogin"/>



            </mx:Application>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下凄凉 2024-10-06 14:14:42

要将单击的按钮的字符添加到 txtLogin,请将您的 clickhandler 更改为:

public function clickhandler(event:Event):void
{
    var button:Button=event.target as Button;
    txtLogin.text += button.label;
}

如果您想替换 txtLogin 的内容,请使用

txtLogin.text = button.label    // = instead of +=

To add the clicked button's character to the txtLogin, change your clickhandler to this:

public function clickhandler(event:Event):void
{
    var button:Button=event.target as Button;
    txtLogin.text += button.label;
}

If you want to replace the contents of the txtLogin instead, use

txtLogin.text = button.label    // = instead of +=
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文