WebView通过URL传值控制div是否显示

Kornan
2020-10-28 / 0 评论 / 270 阅读 / 正在检测是否收录...

protocol.html

...
<div style="position:relative;" id="form">
    <div class="flex">
        <input type="checkbox" id="ck1"/><span class="checkboxText" style="color:#3789c5">阅读并同意《xxx》</span>
    </div>
    <div class="flex">
        <button id="submit" class="round" onclick="join();">同意</button>
    </div>
</div>
...

protocol.js

···
document.addEventListener("DOMContentLoaded",
function() {
    var ckAll = document.getElementById("form") 
    var type = getQueryVariable("type");
    //获得变量后判断是否展示
    if (type == 0) {
        ckAll.style.display = "block";
    } else {
        ckAll.style.display = "none";
    }
});
//获取get变量值
function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
    return (false);
}
···

Webview加载,通过get传值

//0显示,1隐藏
webView.loadUrl("file:///android_asset/about/protocol.html?type=0")
0

评论 (0)

取消