我如何添加一个图像到我的JavaScript/JQuery文件
How can I add an image to my JavaScript/JQuery file?
我想做一个简单的基于浏览器的测验,有图片作为问题和文本答案或反之亦然(这是一个手语测验),我在网上找到了一个测验模板,似乎工作得很好,但对于我的生活,我不知道如何添加图片到问题。
代码:http://codepen.io/jchamill/pen/garoqg
JS代码:
$('#quiz').quiz({
//resultsScreen: '#results-screen',
//counter: false,
//homeButton: '#custom-home',
counterFormat: 'Question %current of %total',
questions: [
{
'q': 'Is jQuery required for this plugin?', // This is where I'd like the photo to be.
'options': [
'Yes',
'No'
],
'correctIndex': 0,
'correctResponse': 'Good job, that was obvious.',
'incorrectResponse': 'Well, if you don''t include it, your quiz won''t work'
},
{
'q': 'How do you use it?',
'options': [
'Include jQuery, that''s it!',
'Include jQuery and the plugin javascript.',
'Include jQuery, the plugin javascript, the optional plugin css, required markup, and the javascript configuration.'
],
'correctIndex': 2,
'correctResponse': 'Correct! Sounds more complicated than it really is.',
'incorrectResponse': 'Come on, it''s not that easy!'
},
{
'q': 'The plugin can be configured to require a perfect score.',
'options': [
'True',
'False'
],
'correctIndex': 0,
'correctResponse': 'You''re a genius! You just set allowIncorrect to true.',
'incorrectResponse': 'Why you have no faith!? Just set allowIncorrect to true.'
},
{
'q': 'How do you specify the questions and answers?',
'options': [
'MySQL database',
'In the HTML',
'In the javascript configuration'
],
'correctIndex': 2,
'correctResponse': 'Correct! Refer to the documentation for the structure.',
'incorrectResponse': 'Wrong! Do it in the javascript configuration. You might need to read the documentation.'
}
]
});
你将不得不分叉并更改插件本身。您想要查看src/jquery.quiz.js
并更改setup
函数。特别是第68行和79行之间的部分:
quizHtml += '<div id="questions">';
$.each(questions, function(i, question) {
quizHtml += '<div class="question-container">';
quizHtml += '<p class="question">' + question.q + '</p>';
quizHtml += '<ul class="answerswers">';
$.each(question.options, function(index, answer) {
quizHtml += '<li><a href="#" data-index="' + index + '">' + answer + '</a></li>';
});
quizHtml += '</ul>';
quizHtml += '</div>';
});
quizHtml += '</div>';
相关文章:
- 我的javascript for循环不起作用
- 如何将我的javascript库公开给其他客户端使用
- 可以Resharper在我的javascript函数声明中添加分号
- 为什么我的JavaScript堆栈排序函数不起作用
- 页面在我的javascript执行后重新加载,我不希望它这样做
- MVC正在忽略我的Javascript文件
- 为什么我的javascript程序没有将其转换为整数而不是字符串
- 为什么我的JavaScript在Safari上的严格模式下不能正常工作
- 我的javascript太慢了
- 由于某种原因,我的JavaScript函数无法工作
- 为什么我的javascript脚本在页面加载时运行,而不是使用onclick
- 我的Javascript代码出错
- 为什么我的javascript和jquery源文件始终不加载
- AJAX:为什么不是't我的javascript与内容一起加载
- 为什么不是't我的javascript向Project Euler返回正确答案's排名第一
- 为什么当我在带有锚点的页面之间移动时,Rails不重新加载我的javascript文件
- Num doenst在我的javascript中工作
- 在我的JavaScript模块中绑定一个点击事件
- 为什么我的JavaScript函数没有返回选中的数组值
- 使用Ajax将我的Javascript变量传递给PHP