2

I have a list of answers attached to sums for my maths game. Each time an answer is randomly selected from the list, it has a sum attached. The problem I am having is that I want the sum to be pulled into a div so it is displayed. I have done this before for images and sounds by using "preload="auto"". What is the equivalent for pulling text through?

Here is the list..

<ul style="display:none;" id="answerlist">

    <li data-answer="1" data-sum="4 - 3 ="></li>

    <li data-answer="2" data-sum="7 - 5 ="></li>

    <li data-answer="3" data-sum="1 + 2 ="></li>

    <li data-answer="4" data-sum="1 + 3 ="></li>

    <li data-answer="5" data-sum="4 - 3 ="></li>

    <li data-answer="6" data-sum="10 - 4 ="></li>

    <li data-answer="7" data-sum="4 + 3 ="></li>

    <li data-answer="8" data-sum="2 x 4 ="></li>

    <li data-answer="9" data-sum="4 + 5 ="></li>

    <li data-answer="10" data-sum="1 x 10 ="></li>

    <li data-answer="11" data-sum="10 + 1 ="></li>

    <li data-answer="12" data-sum="2 x 6 ="></li>

    <li data-answer="13" data-sum="9 + 4 ="></li>

    <li data-answer="14" data-sum="2 x 7 ="></li>

    <li data-answer="15" data-sum="11 + 4 ="></li>

  </ul>

I want to print it through the div..

  <div class="mysum" class="sumstyle">

How would I do this?

Here is a fiddle to help... http://jsfiddle.net/smilburn/ZAfVZ/11/

4

1 回答 1

1

你的小提琴有很多代码要尝试通过。希望这可以帮助

var answer = /* generated somewhere in your code */
var sum= $('#answerlist li[data-answer="'+answer+'"]').data('sum');
$('.mysum').text(sum + answer); 

演示 http://jsfiddle.net/rt44v/

于 2012-10-16T11:31:38.260 回答