首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何动态传递数组索引值

如何动态传递数组索引值
EN

Stack Overflow用户
提问于 2013-09-02 14:16:32
回答 1查看 399关注 0票数 0

我想知道如何动态获取数组索引值。

在这里,我定制了我的代码中使用的quizy- files intheblanks.master.zip文件:

代码语言:javascript
复制
<script>
  $('#tutorial-fillblank').quizyFillBlank({
    textItems:['The first president of the United States of America is', '. The longest serving president of the country is ', '. He was succeeded by ', ', who led the country till the end of the Second World War. The first afro-american to be elected for this position is', '.'],
    anItems:['John Kennedy', 'Franklin Roosevelt', 'George Washington', 'Ronald Reagan', 'Harry Truman', 'Richard Nixon', 'Barack Obama' ], 
    anItemsCorrect:[2,1,4,6],
    blockSize:150
  });
</script>

在上面的代码中,textItems是问题,anItems是答案,anItemCorrect是anItems的数组索引值。

在该编码中,我将从数据库中获得的值自定义为问题和答案。这里我不知道如何动态传递anItemCorrect的值:

代码语言:javascript
复制
<script>
  $('#tutorial-fillblank').quizyFillBlank({
    textItems:[<?php foreach($question as $article)  { echo "'".$article->question."',";}?>],
    anItems:[<?php foreach($question as $article)
    {$a[]=$article->answer;}
    $arr=$a; shuffle($arr); foreach($arr as $ans => $val) {echo "'".$val."',";} ?> ], 
    anItemsCorrect:[<?php foreach($arr as $ans => $val) { echo "'".$ans."',";} ?>],
    blockSize:150
  });
</script>

如何使用jquery.inArray()动态选择答案是对还是错?

EN

回答 1

Stack Overflow用户

发布于 2013-09-02 14:20:59

你不能,因为你打乱了你的问题,所以你不知道答案的顺序。

而不是这样做,使用一个关联的php数组映射question=>answer。然后你就可以洗牌了,秩序就会得到维持。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18566755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档