问题描述
我正在尝试将JSON数据解析为类名slide_content的特定迭代。
I am trying to parse JSON data into specific iterations of a class name "slide_content"
要获得这样的东西:
slide_content[0]
但是JS不提供 getElementByClass()
selector。
But JS doesn't provide a getElementByClass()
selector.
有关API数据在这里:
The API data in question is here:Converting Straight JS to JQuery
干杯!
Myles
Cheers!Myles
推荐答案
使用jQuery。它允许您使用 $('。someClass')
检索具有给定类名的所有元素。
Use jQuery. It allows you to use $('.someClass')
to retrieve all elements with a given class name.
如果由于某种原因您无法使用jQuery或其他JS库,只需使用jQuery也使用的Sizzle选择器引擎 - 它不是很多代码,因此您甚至可以将其复制并粘贴到您的项目的JS文件之一(但不要'这样做,这很丑:p)。但是,由于您使用jquery标记了您的问题,我认为您可以使用jQuery ...
If you cannot use jQuery or another JS library for some reason, simply use the Sizzle selector engine which is also used by jQuery - it's not very much code so you could even copy&paste it into one of your project's JS files (but don't do that, it's ugly :p). But since you tagged your question with jquery I assume you can use jQuery...
这篇关于使用JS定位类名迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!