如何在单击按钮上从一个js页面导航到另一个js页面

时间:2012-07-01 06:48:50

标签: titanium

我对mac os x更新鲜。

我第一次使用钛,对js页面和动作事件没有任何了解

我设置钛并添加按钮。点击按钮,我需要导航到另一个js页面

 var btn = Ti.UI.createButton({

        left:10,
        top:100,        
        height:'40',
        width:'80',
        title:'login',
        color:'auto'
     }  
)
    self.add(lbl);

    btn.addEventListener('click',function() {
    }
        )

让我们考虑第二个js页面是login.js页面

当我点击按钮时,我需要登录.js页面

带导航效果!

@提前感谢

2 个答案:

答案 0 :(得分:3)

使用以下代码

var btn = Ti.UI.createButton({
        left:10,
        top:100,        
        height:'40',
        width:'80',
        title:'login',
        color:'auto'
});
self.add(btn);

btn.addEventListener('click',function() {
    var win = Titanium.UI.createWindow({
        url:'login.js',
        title:'Login'
    });

    Titanium.UI.currentTab.open(win,{animated:true}); //if you used tabbar in your app
    win.open(win,{animated:true}); //if you don't have tabbar in your app
});

希望这有助于你

答案 1 :(得分:0)

此代码可以帮助您

函数ApplicationWindow(){

//declare module dependencies

var All = require('ui/common/All');

    Tree = require('ui/common/Tree');

    EBOM = require('ui/common/E-BOM');

    MBOM = require('ui/common/M-BOM');

    SBOM = require('ui/common/S-BOM');

//create object instance

var self = Ti.UI.createWindow({

    title:'Products',

    exitOnClose:true,

    navBarHidden:true,

    backgroundColor:'#ffffff',
    /////////////////////////////////////////////////////////////////////////////

    activity: {

        onCreateOptionsMenu: function(e) {

            var menu = e.menu;       

            var menuItem = menu.add({ title: "C-BOM", icon: 'Arrow-Hover.jpg' });

            //menuItem.setIcon("Arrow-Hover.jpg");

            menuItem.addEventListener("click", function(e) {

                 var all = new All();

                        self.add(all);
            });



            var menuItem = menu.add({ title: "ALL-BOM" });

            menuItem.setIcon("images/refresh_icon.png");

            menuItem.addEventListener("click", function(e) {

                   var tree = new Tree();

                        self.add(tree);
            });


            var menuItem = menu.add({ title: "E-BOM" });

            menuItem.setIcon("images/refresh_icon.png");

            menuItem.addEventListener("click", function(e) {

                    var ebom = new EBOM();

                        self.add(ebom);
            });

            var menuItem = menu.add({ title: "M-BOM" });

            menuItem.setIcon("images/refresh_icon.png");

            menuItem.addEventListener("click", function(e) {

                    var mbom = new MBOM();

                        self.add(mbom);
            });

            var menuItem = menu.add({ title: "S-BOM" });

            menuItem.setIcon("images/refresh_icon.png");

            menuItem.addEventListener("click", function(e) {

                   var sbom = new SBOM();

                        self.add(sbom);
            });

            var menuItem = menu.add({ title: "Logout" });

            menuItem.setIcon("Arrow-Hover.jpg");

            menuItem.addEventListener("click", function(e) {

                 alert("Logout");

            });

           }

          }

    /////////////////////////////////////////////////////////////////////////////

});

var webview = Titanium.UI.createWebView({

    url:'/ui/common/Login.html'

    });

self.add(webview);


return self;

};

module.exports = ApplicationWindow;