简体   繁体   English

javascript名称空间问题(我认为)

[英]javascript namespace issue (I think)

I've been making a jQuery plugin for password boxes. 我一直在为密码框制作一个jQuery插件。 It adds a generate password button and strength indicator to inputs that are passed to it via a jQuery selector. 它将生成密码按钮和强度指示器添加到通过jQuery选择器传递给它的输入中。

I'm having an issue with the code on lines 154 & 155 of jquery.password.js inputPassword.position().top . 我在jquery.password.js inputPassword.position().top第154和155行上的代码有问题。 It's not returning the correct position of the input box, so the error message isn't appearing in the correct place. 它没有返回输入框的正确位置,因此错误消息没有出现在正确的位置。

I think this is probably an issue with inputPassword not being in the correct namespace, or something like that, but I don't fully understand how these things work in javascript... this is my first jQuery plugin. 我认为这可能是inputPassword不在正确的名称空间或类似名称中的问题,但是我不完全了解这些在javascript中的工作方式。这是我的第一个jQuery插件。

Thanks 谢谢

** link removed *** **链接已删除***

It wasn't namespaces, it was because the object was hidden. 不是名称空间,这是因为对象是隐藏的。 So fixed with: if ( inputPassword.is(":visible") ) { positionObject = inputPassword; } else { positionObject = inputPlain; } 固定为: if ( inputPassword.is(":visible") ) { positionObject = inputPassword; } else { positionObject = inputPlain; } if ( inputPassword.is(":visible") ) { positionObject = inputPassword; } else { positionObject = inputPlain; }

position() returns the offset relative to the parent, however, as the element you're trying to position is positioned absolutely, you might find it works if you use offset() instead. position()返回相对于父级的偏移量,但是,由于您要定位的元素是绝对定位的,因此,如果您改用offset() ,则可能会发现它可以工作。

Edit: inputPassword is hidden whilst you're retrieving the offset() / position() . 编辑:在检索offset() / position() inputPassword隐藏。 From the docs: Note: jQuery does not support getting the offset coordinates of hidden elements. 来自文档: 注意:jQuery不支持获取隐藏元素的偏移量坐标。

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

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