我有以下代码,但它不起作用。我正在尝试创建脚本输出:
<script type="text/javascript">
var files = <?php echo json_encode($files); ?>;
var len = files.length
SLIDES = new slideshow("SLIDES");
for (var i=0; i<len; i++) {
s = new slide();
s.src = "http://www.cashbackflorida.com/wpradmin/modules/wprrets/photos/<?php echo $result ->MLS; ?>/"+ files[i] +;
s.width = "560";
s.height = "420";
s.alt = "";
s.text = unescape("");
s.link = "";
s.target = "";
s.attr = "";
s.filter = "";
SLIDES.add_slide(s);
}
</script>
答案 0 :(得分:0)
您必须将JSON字符串解码为javascript对象。你应该这样做:
<script type="text/javascript">
var xy = <?php echo json_encode($files); ?>;
var files = JSON.parse(xy); /*<- this makes a JavaScript object from JSON string*/
var len = files.length
SLIDES = new slideshow("SLIDES");
for (var i=0; i<len; i++) {
s = new slide();
s.src = "http://www.cashbackflorida.com/wpradmin/modules/wprrets/photos/<?php echo $result ->MLS; ?>/"+ files[i] +;
s.width = "560";
s.height = "420";
s.alt = "";
s.text = unescape("");
s.link = "";
s.target = "";
s.attr = "";
s.filter = "";
SLIDES.add_slide(s);
}
</script>