我使用Cordova构建Android应用程序。我想在触摸菜单按钮时出现div标签。
我使用了 - 06-12 07:08:08.615: W/audio_hw_primary(108): out_write() limiting sleep time 44149 to 23219
- 06-12 07:08:08.635: W/EGL_emulation(3215): eglSurfaceAttrib not implemented
- 06-12 07:08:08.639: W/audio_hw_primary(108): out_write() limiting sleep time 55759 to 23219
- 06-12 07:08:08.659: W/audio_hw_primary(108): out_write() limiting sleep time 47369 to 23219
- 06-12 07:08:08.687: W/audio_hw_primary(108): out_write() limiting sleep time 28979 to 23219
- 06-12 07:08:08.731: W/audio_hw_primary(108): out_write() limiting sleep time 31178 to 23219
事件,但这不起作用。我在模拟器上测试我的应用程序,并通过android监视器检查发现错误。你可以看到下面的日志:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" href="jquery_mobile_1_4_5/themes/jquery.mobile.icons.min.css"/>
<link rel="stylesheet" href="jquery_mobile_1_4_5/jquery.mobile-1.4.5.min.css">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<title>Hello World</title>
</head>
<body>
<header id="header" data-role="header">
<img src="img/logo.png">
</header>
<section data-role="page" id="home-page">
<div data-role="main" class="ui-content">
<div class="pages-buttons">
<a href="#first-home" class="page-button center-button">فهرست محتوا</a>
<a href="#about-book" class="page-button center-button">درباره کتاب</a>
<a href="#about-me" class="page-button center-button">درباره ما</a>
<a href="#setting" class="page-button center-button">تنظیمات</a>
<a href="" class="exit-from-app page-button center-button">خروج از برنامه</a>
</div>
</div>
</section>
<section data-position="fixed" data-role="page" id="about-me">
<div data-role="main" class="ui-content">
<div class="align-center">
</div>
</div>
</section>
<section data-position="fixed" data-role="page" id="about-book">
<div data-role="main" class="ui-content">
<h2 class="post-title">درباره کتاب</h2>
<div class="content">
<img src="img/book.jpg"><br>
</div>
</section>
<section data-position="fixed" data-role="page" id="first-home">
<div data-role="main" class="ui-content">
<h2 class="post-title">فهرست مطالب</h2>
<div id="links">
</div>
</div>
</section>
<section data-role="page" id="setting">
<div data-role="main" class="ui-content">
<h2 class="post-title">تنظیمات</h2>
<div id="content" style="direction: ltr">
<fieldset data-role="controlgroup" class="rtl" data-type="horizontal" data-mini="true">
<legend class="rtl label">نوع فونت </legend>
<input type="radio" name="font-family" id="font-yekan" value="yekan" checked>
<label style="font-family: yekan !important;" for="font-yekan">یکان</label>
<input type="radio" name="font-family" id="font-nazanin" value="nazanin">
<label style="font-family: nazanin !important;" for="font-nazanin">نازنین</label>
<input type="radio" name="font-family" id="font-mitra" value="mitra">
<label style="font-family: mitra !important;" for="font-mitra">میترا</label>
<input type="radio" name="font-family" id="font-terafik" value="terafik">
<label style="font-family: terafik !important;" for="font-terafik">ترافیک</label>
</fieldset>
<br>
<label class="rtl label" for="font-size">اندازه فونت</label>
<input type="range" name="slider-fill-mini" id="font-size" value="19" min="8" max="30" data-mini="true" data-highlight="true" data-theme="a" data-track-theme="d">
<br>
<a data-mini="true" data-inline="true" id="cancel-setting" data-rel="back" data-theme="b" data-role="button" data-icon="delete">Cancel</a>
<input type="button" data-mini="true" data-inline="true" id="save-setting" data-theme="a" data-role="button" data-icon="check" value="Save">
</div>
</div>
</section>
<footer id="footer" data-role="footer">
<div id="back-buttons" class="ui-grid-a">
<div class="ui-block-a align-center">
<a class="icon no-link" data-rel="back" href="#"><i class="fa fa-chevron-left"></i></a>
</div>
<div class="ui-block-b align-center">
<a class="icon no-link" href="#home-page"><i class="fa fa-home"></i> </a>
</div>
</div>
</footer>
<div class="menu-bar">
<div class="menu-grid ui-grid-c">
<div class="menu-block ui-block-a">
<a href="#setting" class="exit-from-app ui-btn ui-btn-inline ui-icon-delete ui-btn-icon-top">خروج</a>
</div>
<div class="menu-block ui-block-b">
<a href="#setting" class="ui-btn ui-btn-inline ui-icon-gear ui-btn-icon-top">تنظیمات</a>
</div>
<div class="menu-block ui-block-c">
<a href="#first-home" class="ui-btn ui-btn-inline ui-icon-back ui-btn-icon-top">فهرست مطالب</a>
</div>
<div class="menu-block ui-block-d">
<a href="#home-page" class="ui-btn ui-btn-inline ui-icon-home ui-btn-icon-top">صفحه اول</a>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="jquery_mobile_1_4_5/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="nice_scroll/jquery.nicescroll.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/shia.js"></script>
</body>
</html>
我的整个index.html:
$(document).ready(onLoad);
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady(){
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
if (typeof window.localStorage.getItem('firstTime') === 'undefined' || window.localStorage.getItem('firstTime') == null)
{
alert('first run');
db.transaction(populateDB);
window.localStorage.setItem('firstTime', 0);
}
$("[data-role='header'], [data-role='footer']").toolbar();
$('body').niceScroll();
$(document).on("pageshow",function(event){
db.transaction(applySetting);
if($.mobile.activePage.attr('id') == 'home-page')
$('#back-buttons').hide();
else
$('#back-buttons').show();
});
$('.exit-from-app').click(exitFromApp);
$('#save-setting').click(function(){
db.transaction(settingQuery);
alert('تنظیمات با موفقیت اعمال شد');
})
document.addEventListener("menubutton", menubutton, false);
db.transaction(applySetting);
}
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS setting');
tx.executeSql('CREATE TABLE IF NOT EXISTS setting (title text, value text)');
tx.executeSql('insert into setting(title, value) values("font_family", "nazanin")');
tx.executeSql('insert into setting(title, value) values("font_size", "19")');
alert('table created');
return true;
}
function errorCB(tx, err) {
alert("Error processing SQL: "+err);
navigator.app.exitApp();
}
function settingQuery(tx)
{
var font_family = $('input[name="font-family"]:checked').val();
var font_size = $('#font-size').val();
tx.executeSql('delete from setting where 1');
tx.executeSql('insert into setting(title, value) values("font_family", "' + font_family + '")');
tx.executeSql('insert into setting(title, value) values("font_size", "' + font_size + '")');
}
function applySetting(tx)
{
tx.executeSql('select * from setting where title = "font_family"', [], function(tx, results){
if(results.rows.length)
{
alert(results.rows[0].value);
$('.content').css('font-family', results.rows[0].value);
if($.mobile.activePage.attr('id') == 'setting')
{
$('input[name="font-family"]').prop( "checked", false ).checkboxradio( "refresh" );
$('input#font-' + results.rows[0].value).prop( "checked", true).checkboxradio( "refresh" );
}
}
});
tx.executeSql('select * from setting where title = "font_size"', [], function(tx, results){
if(results.rows.length)
{
$('.content').css('font-size', results.rows[0].value + 'px');
if($.mobile.activePage.attr('id') == 'setting')
{
$('#font-size').val( results.rows[0].value);
}
}
});
}
function menubutton(){
$('.menu-bar').toggle();
}
function exitFromApp()
{
navigator.app.exitApp();
}
和shia.js:
xpath PM.xml '/*[contains(local-name(),'PM')]/*[contains(local-name(),'family')]/@eventNumber'
答案 0 :(得分:0)
你可以试试这个:
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("menubutton", onMenuKeyDown, false);
}
// Handle the menu button
//
function onMenuKeyDown() {
// add simple testing function
alert('menu button pressed');
$('.menu-bar').toggle();
}
并触发HTML上的onLoad按钮,如下所示:
<body onload="onLoad()">