起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2811|回复: 1

[处理中1] 下面代码打包后手机运行提示this.getElementByXid is not a function

[复制链接]

19

主题

55

帖子

323

积分

中级会员

Rank: 3Rank: 3

积分
323
QQ
发表于 2017-5-20 05:10:13 | 显示全部楼层 |阅读模式
本帖最后由 xichuinfo 于 2017-5-20 05:12 编辑
  1. <p> Model.prototype.modelLoad = function(event){
  2.   document.addEventListener("backbutton", function() {
  3.    if (localStorage.getItem("canExit") == "1") {
  4.     if (!this.exitMsg) {
  5.      this.exitMsg = new MsgDialog({
  6.       parentNode : this.getElementByXid("buttons")
  7.       });
  8.     }
  9.     this.exitMsg.on('onYes', function(event) {
  10.      navigator.app.exitApp();
  11.      }, this);
  12.     this.exitMsg.show({
  13.      type    : "YesNo",
  14.      title   : "提示",
  15.      message : "您确认退出系统吗?"
  16.                 });
  17.    } else {
  18.     justep.Shell.closePage();
  19.    }
  20.   }, false);
  21. };
  22. </p>
复制代码


上面代码打包后手机运行提示this.getElementByXid is not a function
请问什么情况?

31

主题

1856

帖子

3070

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3070
发表于 2017-5-20 14:41:49 | 显示全部楼层
你这this不对啊,建议看下js对于this相关的介绍。你这个要正确,可如下
Model.prototype.modelLoad = function(event){
   var self = this;  // 注意,这个是关键
document.addEventListener("backbutton", function() {
   // 你这里是回调,下面的this就肯定不是上面那个this了,你可用self来代替,上面做了赋值  self.getElementByXid
   if (localStorage.getItem("canExit") == "1") {
    if (!this.exitMsg) {
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-22 16:10 , Processed in 0.065785 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表