jsPsych/examples/jspsych-text.html
2013-11-10 21:59:46 -05:00

44 lines
1.8 KiB
HTML

<!doctype html>
<html>
<head>
<title>jspsych-text plugin example</title>
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<!-- jsPsych -->
<script src="scripts/jspsych.js"></script>
<script src="scripts/plugins/jspsych-text.js"></script>
<!-- style -->
<style>
#jspsych_target { margin: 50px auto 50px auto; width: 600px; font-size:18px; text-align: center;}
#instructions { text-align: left; }
pre { text-align: left; }
</style>
</head>
<body>
<div id="jspsych_target">
</div>
</body>
<script type="text/javascript">
// declare variable to hold instructions
var instructions_part_1 = '<div id="instructions"><p>The first part of the instructions. Any HTML code can be used here.</p><p>Press ENTER to continue.</p></div>';
var instructions_part_2 = '<div id="instructions"><p>Variables can also be put in the text, like this: %v</p><p>Press ENTER to continue.</p></div>';
// this is a simple function, but any function can be used to put a variable into
// the text block as long as it returns a string.
var variable_function = function(){ return "This is a variable."; };
// create the text block
var text_block = {type:'text', text: [instructions_part_1,instructions_part_2], variables:[[],[variable_function]]};
// launch jspsych
jsPsych.init({
display_element: $('#jspsych_target'),
experiment_structure: [text_block],
on_finish:function(data){
$('#jspsych_target').append($("<pre>",{
html: JSON.stringify(data,undefined,2)
}));
}
});
</script>
</html>