3

我是跨平台 Titanium SDK 和 Alloy MVC 框架的新手。

我在 index.xml 中创建了一个按钮,如下所示:

 <Alloy>
    <Button id="button">Click Me</Button>
</Alloy>

但现在我想知道如何在 iPhone 上显示标题“Click Me”,在 iPad 上显示标题“Submit”。

我需要在哪里写条件?在 index.xml、index.js 或 index.tss 中?

4

1 回答 1

7

您可以通过以下几种方式来执行此操作,或者在 index.xml 文件中,如下所示:

<Alloy>
    <Button formFactor="handheld" id="button">Click Me</Button>
    <Button formFactor="tablet" id="button">Submit</Button>
</Alloy>

或者像这样在 index.js 中:

if(Alloy.isHandheld) {
    $.button.title = "Click Me";
}

if(Alloy.isTablet) {
    $.button.title = "Submit";
}

或者在样式文件中,index.tss 是这样的:

"#button[formFactor=handheld]" : { 
    title : "Click Me"
},

"#button[formFactor=tablet]" : { 
    title : "Submit"
}
于 2013-04-28T15:20:49.883 回答