TimeSpinner Check If Undefined does not work

综合技术 Hello, buddy! (源链)

Currently I have a an input text field that may or may not have a timespinner tied to that particular element. In some cases, I need to remove the timespinner functionality altogether (as opposed to disabling it), to display it properly on the page.

Currently, I have code to check if the timespinner exists on the element as follows:

if ($("#ElementOfInterest").timespinner !== undefined){

This works fine when the page is first loaded, however, this throws the following exception:

cannot call methods on timespinner prior to initialization; attempted to call method 'destroy'

For some reason, the check for undefined
passes and tries to a timespinner on the element that doesn’t exist.

So the only way for my UI to run properly at the moment is to wrap it in a try/catch
block like this:

if ($("#ElementOfInterest").timespinner !== undefined) {
    try {
    } catch (error) {

This works, but it is rather sloppy. I would rather have the check be successful and remove the try/catch
block from the code.

Am I missing some special check or something? What’s going on here?


I tried the following code suggested by @GlenSwift:

if (typeof $("#ElementOfInterest").spinner("instance") !== 'undefined') {

This however, gave me this exception:

cannot call methods on spinner prior to initialization; attempted to call method 'instance'

I also tried timespinner("instance")
but I simply got back:

undefined is not a method

So it looks like checking for an instance of a timespinner was not implemented.

Well $("#ElementOfInterest").timespinner !== undefined
just checks if $().timespinner
is defined, which it will be as long as the plugin is loaded. How about checking if the element has the class the the spinner adds. if ($("#ElementOfInterest").hasClass('ui-spinner-input'))


Adding some options with javascript i currently have an empty drop down list that I would like to fill with some data I got from my database using javascript. I really have no idea h...
Javascript storage based queue mechanism for brows... Storage Based Queue on Browser Storage based queue processing mechanism. Today, many backend technology is a simple derivative of the queuing system...
百度外卖前端周刊 – 第34期 精彩的2017年过去了,bestofjs 产出了一份2017明星项目的总结, 2017 JavaScript Rising Stars ,借此契机,本期前端周刊以“开源项目”为主题,给大家推荐了一些,star数排名比较高,但是又不是特别知名的有用的&好玩的Github JavaS...
JavaScript机器学习之线性回归 译者按:AI时代,不会机器学习的JavaScript开发者不是好的前端工程师。 原文: Machine Learning with JavaScript : Part 1 译者:Fundebug 为了保证可读性,本文采用意译而非直译。另外,本文版权归原作者所有,翻译仅用于学习...
Elm – JavaScript reinvented (Part 2) This is second part of my article about the Elm programming language.On the first article I focused on the main features that make Elm an interesting...
Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » TimeSpinner Check If Undefined does not work

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录