mui---webview对象调用evalJS来传递参数

evalJS_send_page.html(发送页面)

<!doctype html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link href="css/mui.min.css" rel="stylesheet" />
    </head>

    <body>
        <button id="btn_send" type="button" class="mui-btn mui-btn-blue">发送页面执行接收页面定义的函数并传参</button>
        <script src="js/mui.min.js"></script>
        <script type="text/javascript">
            mui.init();
            var ws = null;
            mui.plusReady(function() {
                //如果使用html5+api,如plus.barcode,plus.webview,plus.nativeUI等需要放入plusReady事件中,而且要用真机运行
                ws = plus.webview.create('evalJS_recieve_page.html', 'evalJS_recieve_page');
            });
            document.getElementById("btn_send").addEventListener('tap', function() {
                var name = 'mike';
                ws.evalJS('get_para("' + name + '")'); //evalJS执行字符串里的js代码
                ws.show();
            })
        </script>
    </body>

</html>

 

evalJS_recieve_page.html(接收页面)

<!doctype html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link href="css/mui.min.css" rel="stylesheet" />
    </head>

    <body>
        <div class="mui-content">
            <div id="div1"></div>
        </div>
        <script src="js/mui.min.js"></script>
        <script type="text/javascript">
            mui.init();
//            定义一函数给发送页面调用,获得其传入的参数
            function get_para(para) {
                document.getElementById("div1").innerText='hi,'+para;
            }
        </script>
    </body>

</html>

 

posted @ 2018-05-30 21:06  框框A  阅读(945)  评论(0编辑  收藏  举报