javascript JSSOR - 无法读取未定义的类型属性“currentStyle”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25206272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSSOR - Cannot read type property 'currentStyle' of undefined
提问by DanTheMan
I'm trying to implement the Jssor slider into my page, but I keep coming up with that error in the title.
我正在尝试在我的页面中实现 Jssor 滑块,但我一直在标题中出现该错误。
My content is being dynamically created via Javascript, like so:
我的内容是通过 Javascript 动态创建的,如下所示:
var slide = app.createHTML('div', "", {'id':'inventorySlides'}, null);
var div = document.getElementById('invDiv');
div.appendChild(slide);
and then I procedurally generate cell divs in the same way and append them to slide
.
然后我以相同的方式在程序上生成单元格 div 并将它们附加到slide
.
I've defined a function in my main controller as in the example on the basic usage page (http://www.jssor.com/development/basic-usage-no-jquery.html), and after all the content has been generated and appended, I call the function
我已经在我的主控制器中定义了一个函数,如基本用法页面(http://www.jssor.com/development/basic-usage-no-jquery.html)上的示例,毕竟内容已经生成并附加,我调用函数
jssor_slider1_starter('inventorySlides');
But then I get the error message in the console. I've tried logging the inventorySlides div, and it definitely exists in the DOM, so I know it's not that. I tried searching for currentStyles
, which turns out is just on IE and Opera, and I'm using Chrome.
但是后来我在控制台中收到错误消息。我试过记录inventorySlides div,它肯定存在于DOM 中,所以我知道它不是那样的。我尝试搜索currentStyles
,结果只在 IE 和 Opera 上搜索,我使用的是 Chrome。
So is it something I'm doing wrong? Or is it Jssor that's misbehaving?
那么这是我做错了什么吗?或者是 Jssor 行为不端?
采纳答案by DanTheMan
So firstly, I had forgotten to include jssor.core.js and jssor.utils.js, though that did not fully solve my problem.
所以首先,我忘记包含 jssor.core.js 和 jssor.utils.js,尽管这并没有完全解决我的问题。
The Solution was that I needed to create a div with an attribute u="slides"
, which goes inside the 'inventorySlides' div, and the cells are nested inside this new div
解决方案是我需要创建一个带有属性的 div u="slides"
,它位于“inventorySlides”div 内,并且单元格嵌套在这个新 div 内
NOTE: I made this answer much later than when it was asked because at the time I did not have enough reputation to be able to answer my own question, and now I no longer have access to the code this question is referencing, so I can't really add much more detail to the answer than what had already been discussed in the comments. I apologize if there's any details you need that this answer does not provide, but I can't help much past this point. Cheers - Dan
注意:我回答这个问题的时间比被问到的时间要晚得多,因为当时我没有足够的声誉来回答我自己的问题,现在我无法再访问这个问题所引用的代码,所以我可以与评论中已经讨论的内容相比,并没有真正为答案添加更多细节。如果您需要此答案未提供的任何详细信息,我深表歉意,但在这一点上我无能为力。干杯 - 丹
回答by Emre Erol
If you are including jssor.js file after the html slider elements, then you are getting same error.
如果在 html 滑块元素之后包含 jssor.js 文件,则会出现相同的错误。
The solution : include jssor.js file bottom of the page.
解决方案:在页面底部包含 jssor.js 文件。