如何在JSON中使用if語句這裏是代碼: ................................... .................................................. ..如何使用JSON內部的if語句?
var config =
[
{
"name" : "SiteTitle",
"bgcolor" : "",
"color" : "",
"position" : "TL",
"text" : "step1",
"time" : 5000
},
{
"name" : "Jawal",
"bgcolor" : "",
"color" : "",
"text" : "step2",
"position" : "BL",
"time" : 5000
},
{
"name" : "Password",
"bgcolor" : "",
"color" : "",
"text" : "step3",
"position" : "TL",
"time" : 5000
}
],
//define if steps should change automatically
autoplay = false,
//timeout for the step
showtime,
//current step of the tour
step = 0,
//total number of steps
total_steps = config.length;
這是需要的結果是這樣的:
var config =
[
if(page==true) {
{
"name" : "SiteTitle",
"bgcolor" : "",
"color" : "",
"position" : "TL",
"text" : "step1",
"time" : 5000
},
{
"name" : "Jawal",
"bgcolor" : "",
"color" : "",
"text" : "step2",
"position" : "BL",
"time" : 5000
}
} else {
{
"name" : "Password",
"bgcolor" : "",
"color" : "",
"text" : "step3",
"position" : "TL",
"time" : 5000
}
}
],
//define if steps should change automatically
autoplay = false,
//timeout for the step
showtime,
//current step of the tour
step = 0,
//total number of steps
total_steps = config.length;
其實這種方法是錯誤的,使得JavaScript語法錯誤。
這將使一個語法錯誤,因爲你有互補碼 ,自動播放=假, 欣欣, step = 0, total_steps = config.length; – 2013-02-25 07:34:31
@ MontaserEl-sawy:不,不是。嘗試一下。 – Blender 2013-02-25 07:35:57
試過它的代碼將是: 如果(settingsPage){ \t \t \t \t變種配置= [ \t \t \t \t { \t \t \t \t \t 「名稱」: 「SiteTitle」, \t \t \t \t \t 「bgcolor」:「」, \t \t \t \t \t 「顏色」: 「」, \t \t \t \t \t 「位置」: 「TL」, \t \t \t \t \t 「文」: 「第一步」, \t \t \t \t \t 「時間」:5000 \t \t \t \t} \t \t \t \t \t \t \t \t]; \t \t \t}其他{ \t \t \t \t無功配置= [ \t \t \t \t { \t \t \t \t \t 「名」 「密碼」, \t \t \t \t \t 「的bgcolor」: 「」, \t \t \t \t \t「color」:「」, \t \t \t \t \t 「文」: 「第三步」, \t \t \t \t \t 「位置」: 「TL」, \t \t \t \t \t 「時間」:5000 \t \t \t \t} \t \t \t \t ]。 \t \t \t} \t \t \t \t, \t \t \t \t \t自動播放= FALSE, \t \t \t \t放映時間, \t \t \t \t \t步驟\t = 0, \t \t \t \t TOTAL_STEPS \t = config.length; 試試看,並告訴我會發生什麼? – 2013-02-25 07:44:31