您好,我想使用 RandomQuoteGenerator 脚本,我在 stackoverflow 上找到了一个脚本,但我希望它不重复引号,我在这里找到了一个解决方案,但它对我不起作用。单击按钮时出现未定义的错误。上面链接中提供的原始脚本工作正常,但如果我更改上面链接中提到的函数,我将收到未定义的消息而不是引号。我的 Generator.jsvar quotes = [//success quotes { quote: "If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success.", source: "James Cameron", tag: "success" }, { quote: "The Way Get Started Is To Quit Talking And Begin Doing", source: "Walt Disney", tag: "success" }, { quote: "Don’t Let Yesterday Take Up Too Much Of Today.", source: "Will Rogers", tag: "success" }, { quote: "We Generate Fears While We Sit. We Overcome Them By Action", source: "Dr. Henry Link", tag: "success" },//health quotes { quote: "Early to bed and early to rise, makes a man healthy wealthy and wise.", source: "Benjamin Franklin", tag: "health" }, { quote: "Let food be thy medicine and medicine be thy food.", source: "Hippocrates", tag: "health" }, { quote: "If you can’t pronounce it, don’t eat it.", source: "Common Sense", tag: "health" }, { quote: "Health is like money, we never have a true idea of its value until we lose it.", source: "Josh Billings", tag: "health" },//spirituality quotes { quote: "Life is really simple, but men insist on making it complicated.", source: "Confucius", tag: "spirituality" }, { quote: "My religion is very simple. My religion is kindness.", source: "Dalai Lama", tag: "spirituality" }, { quote: "Knowing others is wisdom; knowing the self is enlightenment.", source: "Tao Te Ching", tag: "spirituality" }, { quote: "When there is love in your heart, everything outside of you also becomes lovable.", source: "Veeresh", tag: "spirituality" }];
1 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
您的函数getRandomQuote()
返回一个数组,因此为了访问该对象,您需要访问该数组的第一个元素。像这样...
getQuote[0].quote
添加回答
举报
0/150
提交
取消