2013-02-17 102 views
1

我有這段代碼。在'內容'部分,我想要顯示一個變量 - currentCard - 。在jQuery插件中使用javascript variavl

這是代碼。任何幫助深表感謝!

$("#middle").flip({ 
    direction:'rl', 
    content:'currentCard', 
    color:'#fff' 
}) 
+0

那就不要把它放在引號? – 2013-02-17 14:56:47

+0

我試過了,那不起作用。 – spogebob92 2013-02-17 14:57:26

回答

1

這很奇怪,沒有引號是不是爲你工作,試試這個代碼:

var currentCard = "card123"; 
console.log(currentCard); 

$("#middle").flip({ 
    direction:'rl', 
    content:currentCard, 
    color:'#fff' 
}) 

要查看控制檯輸出,使用瀏覽器或螢火蟲的開發工具。

如果此代碼適用於「cart123」,請刪除定義currentCard的行並保留控制檯打印以確保此變量的值是您認爲的值。

1

應該不是你的代碼說:

$("#content").flip({ //changed to 'content' from 'middle' 
direction:'rl', 
content:currentCard, //remove the quotes, because with the quotes, it'll anyway never get the value of the variable. 
color:'#fff' 
}); 
+0

另外,請確保您的變量「currentCard」具有一個值,並且可以在運行時通過此代碼訪問。 – 2013-02-17 15:05:10