You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何出现“ReferenceError: askMe is not defined”?jBox测试调试求助

解决"askMe is not defined"的问题

嘿,我一眼就揪出你代码里的小问题啦!报错的根源其实在HTML代码里,两个语法错误导致浏览器没法正确识别askMe函数:

  • 多余的双引号:你写的<span onclick="askMe" ">Click me</span>里,"askMe" "部分多了一个双引号,这会打乱浏览器对属性值的解析逻辑。
  • 函数调用未加括号:要触发函数必须写askMe(),而不是askMe——后者只是引用函数本身,并不会执行它。

修正后的完整代码:

HTML部分:

<span onclick="askMe()">Click me</span>

JS部分(这部分本身没问题,保持原样即可):

var jb;
function askMe() {
  console.log(jb);
  jb.Open({"confirmButton": "new confirm-text here!"});
};
$(function(){
  jb = new jBox( "Confirm", {
    "cancel":function() {$(document).trigger("event_no");},
    "cancelButton":"No",
    "confirm":function(){$(document).trigger("event_yes");},
    "confirmButton":"Yes",
    "content":"Do you like this sample?",
    "title":"Your choice, please!"
  } );
});

修改后再点击"Click me",就能正常调用askMe函数,不会再出现"askMe is not defined"的报错啦。

内容的提问来源于stack exchange,提问作者MBaas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:14:08