cordova震动蜂鸣器输入参数

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <!--
        Customize this policy to fit your own app's needs. For more guidance, see:
            https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
        Some notes:
            * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
            * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
            * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                * Enable inline JS: add 'unsafe-inline' to default-src
        
        <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 *; img-src 'self' data: content:;">
        <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" type="text/css" href="css/index.css">-->
        <meta name="viewport" content="user-scalable=yes, initial-scale=1, maximum-scale=2, minimum-scale=0.5">
        <meta charset='utf-8'>
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p><br>
                <form>
                <input type="text" id="inputnum" value="0">
                </form>
                    <button id='vibration'>震动</button><br><br><br>
                    <button id = "beep">发声</button>
                    <button id='dispbutton'>显示信息</button>
                    <p id="dispnum"></p>
            </div>
            
        </div>
        <script>
            var num=document.getElementById('inputnum');//读text地址
            function beginVabration(){//震动回调函数
                navigator.vibrate(num.value*1000);               
            } 
            function beginBeep(){/发声回调函数
                navigator.notification.beep(num.value);
            }
            function disp(){//显示回调函数
                document.getElementById("dispnum").innerHTML=num.value;
            }
        </script>

        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>


功能实现,在text框中输入要震动的时长和要发声的次数,本程序为了简单就把这个数合并成一个了,其中红色部分是自己添加的代码,上面是HTML代码,下面是添加的js代码

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');

       // console.log(navigator.vibrate);
        //console.log(navigator.notification);
        document.getElementById('vibration').addEventListener('click',beginVabration);//这三个函数都是按钮的事件监听
        document.getElementById('beep').addEventListener('click',beginBeep);
        document.getElementById('dispbutton').addEventListener('click',disp);
    },

震动按钮,发声按钮,显示信息按钮(用来输出text中的信息,查看读值是否准确)

调试出现的问题

1.按钮监听,两种方法,第一种如程序所示,在js中添加的红的代码

     第二种方法<button id='   ' οnclick='   函数名 ' >按钮上要显示的内容</button>

2.读text值时出现的问题

第一次的写法var num=document.getElementById('inputnum').value;   结果怎么也读不过来值,不知道为什么,愿意待查

第二次的写法如程序中所示,先读text的地址var num=document.getElementById('inputnum');     

        引用时在读值num.value就是可以的


写的有点乱,


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值