我在从其他文件中包含函数时遇到问题。
我在responsive.js中有2个文件app.js
和responsive.js
,我有这个:
// 100%
var per100 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 1.0);
// 90%
var per90 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.9);
// 80%
var per80 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.8);
// 60%
var per50 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.6);
// 50%
var per50 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.5);
// 40%
var per40 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.4);
// 25%
var per25 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.25);
// 10%
var per10 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.10);
// 5%
var per5 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.5);
// 1%
var per1 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.1);
并在app.js
文件中我有:
// include needed files
Ti.include('responsive.js');
//Create the screen
//The home screen
var homeWindow = Ti.UI.createWindow({
exitOnClose: true,
fullscreen: false,
title: 'Advanced'
});
var homeView = Ti.UI.createView({
backgroundColor: 'white'
});
var homeLabel = Ti.UI.createLabel({
top: 20,
left: 30,
height: 30,
text: 'Login or register to start',
color: 'black',
font: {fontSize: 18}
});
var homeLoginButton = Ti.UI.createButton({
title: 'test',
backgroundColor: 'red',
top: 55,
left: 30,
width:per60,
height: 30,
color: 'black',
font: {fontSize: 14}
});
var homeRegisterButton = Ti.UI.createButton({
title: 'test2',
backgroundColor: 'blue',
top: 55,
left: 180,
width:per60,
height: 30,
color: 'black',
font: {fontSize: 14}
});
//Creating the application
//Home screen
homeWindow.add(homeView);
homeView.add(homeLabel);
homeView.add(homeLoginButton);
homeView.add(homeRegisterButton);
homeWindow.open();
一切都很简单但每次我尝试启动应用程序时都会收到此错误
Uncaught Reference error: per60 is not defined
我该如何解决这个问题?
答案 0 :(得分:1)
你似乎有两次:
var per50
且没有
var per60
在你的第一个文件中