<!-- 2.) Create a UI5 button and place it onto the page -->
<script>
// create the button instance
Var myButton = new sap.ui.commons.Button("btn");
// set properties, e.g. the text (there is also a shorter way of setting several properties)
myButton.setText("Hello World!");
// attach an action to the button's "press" event (use jQuery to fade out the button)
myButton.attachPress(function(){$("#btn").fadeOut()});
// place the button into the HTML element defined below
myButton.placeAt("uiArea");
// an alternative, more jQuery-like notation for the same is:
/*
$(function(){
$("#uiArea").sapui("Button", "btn", {
text:"Hello World!",
press:function(){$("#btn").fadeOut();}
});
});
*/
</script>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>Mobile App Example</title>
<!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->
<script id="sap-ui-bootstrap"
src="http://localhost:8080/openui5/resources/sap-ui-core.js"
data-sap-ui-libs= "sap.m"
data-sap-ui-theme= "sap_bluecrystal">
</script>
<script>
// create a mobile App
var app = new sap.m.App("myApp", {
initialPage:"page1"});
var page1 = new sap.m.Page("page1", {
title: "Initial Page",
content : new sap.m.Button({
text : "Go to Page 2",
press: function() {
app.to("page2");
}
})
});
var page2 = new sap.m.Page("page2", {
title: "Page 2",
showNavButton: true,
navButtonPress: function(){
app.back();
}
});
var oTextarea = new sap.m.TextArea({
value : "output area",
width : "100%",
rows : 12
});
var oButton = new sap.m.Button({
text: "Click to get Device Information",
enabled: true,
press : function() {
var output = "";
for (property in sap.ui.Device.system.SYSTEMTYPE) {
var systemtype = sap.ui.Device.system.SYSTEMTYPE[property];
output += systemtype + ': ' + sap.ui.Device.system[systemtype] +';\n';
}
oTextarea.setValue(output);
}
});
page2.addContent(oButton);
page2.addContent(oTextarea);
app.addPage(page1).addPage(page2); // add both pages to the App
app.placeAt("content"); // place the App into the HTML document
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>
http://localhost:8080/ex1/index2.html 打开浏览器的开发者工具,以Chrome为例,按F12,选择Device为 Apple iPhone 6,并按F5刷新,你应该可以看到如下界面: 点击Go to Page2,切换到第二个页面,然后点击Click to get Device Information,可以得到当前设备的信息。