以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 查看微信位置,js的alert不显示 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=150495) |
-- 作者:zhangjian222200 -- 发布时间:2020/5/31 17:37:00 -- 查看微信位置,js的alert不显示 页面代码: wb.AppendHTML("<script src=\'http://res.wx.qq.com/open/js/jweixin-1.4.0.js\'></script>",True) \'引入JS-SDK库 wb.AppendHTML("<script src=\'./lib/ajaxform_****.js\'></script>") \'引入脚本文件 ****** \'在页面注入权限验证配置 Dim st As New Date(1970,1,1,8,0,0) Dim appid As String = Vars("appid") \'开发者ID Dim timestamp As Integer = CInt((Date.Now - st).TotalSeconds()) \'时间戳 Dim noncestr As String = Rand.NextString(16) \'随机字符 Dim url As String = e.Request.URL.ToString \'当前页面地址 Dim signature As String = Functions.Execute("GetJsSignature", noncestr, timestamp, url) \'生成权限验证签名 Dim cfg As String = "wx.config({appId:\'{0}\',timestamp:{1},nonceStr:\'{2}\',signature:\'{3}\',jsApiList:[\'openLocation\']});" wb.InsertHTML("<script>" & CExp(cfg,appid,timestamp,noncestr,signature) & "</script>",True) \'wb.InsertHTML("<script>" & CExp(cfg,appid,timestamp,noncestr,signature) & "</script>") With wb.AddButtonGroup("bt3","btg3",False) .Add("btn11", "位置地图", "button") ’进入页面+点这个按钮,下面的alert没有反应;web开发者工具和服务器,都没有报错; .Add("btn2s2", "视频教程", "submit","/shipin_guanli_shenhsj_lb_xq.htm") End With js代码: wx.ready(function () { alert("ok"); ’这个alert不能显示 if(document.getElementById(\'btn11\')) { alert("ok"); ’这个alert不能显示 var latitude; // 纬度,浮点数,范围为90 ~ -90(手机获得的纬度) var longitude; // 经度,浮点数,范围为180 ~ -180。(手机获得的经度) latitude = document.getElementById("latitude").value; longitude = document.getElementById("longitude").value; document.getElementById(\'btn11\').onclick = function () { wx.openLocation({ //获得坐标后,直接打开微信内置地图 latitude: latitude, // 纬度,浮点数,范围为90 ~ -90 longitude: longitude, // 经度,浮点数,范围为180 ~ -180。 //name: \'\', // 位置名 //address: \'\', // 地址详情说明 scale: 3, // 地图缩放级别,整形值,范围从1~28。默认为最大 //infoUrl: \'\' // 在查看位置界面底部显示的超链接,可点击跳转 }); } } }); //顶部到此,全部结束 wx.error(function (res) { alert(res.errMsg); }); 其他js是验证并用于后续post保存数据的,使用正常
[此贴子已经被作者于2020/5/31 18:55:59编辑过]
|
-- 作者:有点蓝 -- 发布时间:2020/5/31 21:42:00 -- 首先,这个按钮和alert没有半毛钱的关系,既没有绑定调用的代码,也无法调用。按钮点击只能调用【document.getElementById(\'btn11\').onclick = function () {】这里的js函数里面的代码。 其次、如果微信用户不同意公众号使用位置信息的,是用不了位置的相关功能的。 最后、代码改改 wb.AppendHTML("<script src=\'./lib/ajaxform_****.js\'></script>") 改为 wb.AppendHTML("<script src=\'./lib/ajaxform_****.js\'></script>",true) wb.InsertHTML("<script>" & CExp(cfg,appid,timestamp,noncestr,signature) & "</script>",True) 改为 wb.AppendHTML("<script>" & CExp(cfg,appid,timestamp,noncestr,signature) & "</script>") 按钮调式代码加到这里 document.getElementById(\'btn11\').onclick = function () { alert("ok"); wx.openLocation({ //获得坐标后,直接打开微信内置地图 latitude: latitude, // 纬度,浮点数,范围为90 ~ -90 longitude: longitude, // 经度,浮点数,范围为180 ~ -180。 //name: \'\', // 位置名 //address: \'\', // 地址详情说明 scale: 3, // 地图缩放级别,整形值,范围从1~28。默认为最大 //infoUrl: \'\' // 在查看位置界面底部显示的超链接,可点击跳转 }); } |