gpt4 book ai didi

javascript - 返回未定义且所有变量正确

转载 作者:行者123 更新时间:2023-12-02 17:07:34 26 4
gpt4 key购买 nike

所以当我用一些 JavaScript 制作“帮助”页面时出现错误,我不知道为什么会发生这种情况,因为我已经以相同的方式完成了并且工作正常。

当我在输入中输入 help 并按下提交按钮时,发生了错误,它显示一条警告,告诉我 [Object object]。 我正在尝试打印 help 变量 上的第一个 "help" 字符串。

这是 fiddle :http://jsfiddle.net/3u272/

这是代码

//  Toda la ayuda esta guardada en esta cadena de variables
var help = {
"help" : {
title : "help",
description : "Utiliza help mas una de las funciones de a continuación.",
},
};


// Funcion para mostrar la ayuda
var ayudaSubmit = document.form.buscar;
$(ayudaSubmit).on("click", function () {
var helpInputVal = document.form.ayuda.value,
helpQuestion = help[helpInputVal];
if (!helpQuestion) {
alert(helpInputVal + " MEEEEEH!");
} else {
alert(helpQuestion);
};
});

这里是 HTML

<form name="form">
<input name="ayuda" type="text" placeholder="help with + la funci&oacute;n" id="helpInput"/>
<input name="buscar" type="submit" placeholder="Buscar" value="Buscar" id="ayudaSubmit"/>
</form>

最佳答案

您正在向整个对象发出警报。您可能只想提醒消息:将第二个 alert() 更改为:

alert(helpQuestion.description);

结果:

enter image description here

关于javascript - 返回未定义且所有变量正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25108341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com