简体   繁体   English

函数返回jQuery元素返回undefined

[英]Function returning jQuery element returns undefined

I want to write a JS function which returns the first button element from the given container, I have written following code, 我想编写一个JS函数,它返回给定容器中的第一个按钮元素,我编写了以下代码,

let getLastWizardFooterBtn = function(wizardContainer) {
  let wizardFooter = $(wizardContainer).find('.wizard-footer');
  return $(wizardFooter).find('button:enabled:last');
};

But the issue is that even-though I have a DOM element present, this function returns undefined. 但问题是,即使我有一个DOM元素,这个函数返回undefined。

Here are the screenshots from Chrome developer tools. 以下是Chrome开发者工具的屏幕截图。

在此输入图像描述

But as I have debugger set on this line and when I run the same function in Console Tab, I get proper output. 但是由于我在此行上设置了调试器,并且当我在Console选项卡中运行相同的功能时,我得到了正确的输出。

在此输入图像描述

在此输入图像描述

在此输入图像描述

The strange thing is that the variables which I declare are showing undefined but those auto generated variables starting with _ is showing correct values. 奇怪的是,我声明的变量显示未定义,但那些以_开头的自动生成的变量显示正确的值。

在此输入图像描述

Can someone please point out why it is behaving like this? 有人可以指出它为什么会这样吗?

(Because as you can see that I am listening KeyDown event on that container so that DOM element is present for sure.) (因为您可以看到我正在该容器上侦听KeyDown事件,以确保DOM元素存在。)

Thanks in advance. 提前致谢。

====================== ======================

UPDATE: Issue got resolved once I change the variable names as suggested by Christoph Herold in comment sections 更新:一旦我在评论部分中按照Christoph Herold的建议更改变量名称,问题就得到了解决

I assume, something breaks during your minification process, or some code just wasn't properly updated. 我假设,在缩小过程中会出现问题,或者某些代码没有正确更新。 Try renaming your variable or using the unminified code to see, if that at least works. 尝试重命名您的变量或使用未明确的代码来查看,如果这至少有效。 The basic code looks correct. 基本代码看起来正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM