2012-07-02 54 views
-1

我有一个标题和图像的旋转木马。点击图像时,问题/标题会改变。我在编写函数/代码时遇到了麻烦,这将允许我通过onClick的questionList数组增加值。通过使用onclick添加数组 - Javascript

var mycarousel_questionList= [ 
{qID: 1, title: "Question 1"}, 
{qID: 2, title: "Question 2"}, 
{qID: 3, title: "Question 3"}, 
]; 

^^这是我的阵列

function mycarousel_questionListInc(){ 
    pages=mycarousel_questionList.length; 
    var pageNo=0; 
    document.onclick=pageNo++; 
    mycarousel_questionList[pageNo].title; 
} 

^^什么我迄今。 预先感谢您。

+1

你有任何HTML一起去吗? –

+0

我对此很陌生,所以我不太确定。我不这么认为。 – iamtheuser

+0

我很确定你有没有在这里显示的代码;根据你所展示的内容判断,@ Bergi的答案应该可行。 –

回答

0

您将需要设置你已经具备的功能作为event listener

var pageNo=0; 
function mycarousel_questionListInc(){ 
    pages=mycarousel_questionList.length; 
    pageNo++; 
    mycarousel_questionList[pageNo].title; 
} 
document.onclick = mycarousel_questionListInc; 
+0

它没有工作。问题/标题在点击2次后出现为Question1Question1,依此类推。 – iamtheuser

+0

它的确如此。但是没有任何代码可以让任何标题“出现”,请向我们展示您的完整代码(和html页面)。 – Bergi

相关问题