日期:2014-05-17  浏览次数:20538 次

像这样的js,怎样绑定
像这样的jquery轮切的图片,图片是固定,
<SCRIPT type=text/javascript>
  $("#slide").jdSlide({
  width: 766 ,
  height: 250,
  pics: [{
  src:
(screen.width >= 1200) ? "images/a1.jpg" : "images/a1.jpg",
  href: "http://www.baidu.com",
  alt: "",
  breviary: "#",
  type: "img"
  }, {
  src:
(screen.width >= 1200) ? "images/a2.jpg" : "images/a2.jpg",
  href: "#",
  alt: "",
  breviary: "#",
  type: "img"
  }, {
  src:
(screen.width >= 1200) ? "images/a3.jpg" : "images/a3.jpg",
  href: "#",
  alt: "",
  breviary: "#",
  type: "img"

  }, {
  src:
(screen.width >= 1200) ? "images/a4.jpg" : "images/a4.jpg",
  href: "#",
  alt: "",
  breviary: "#",
  type: "img"
  }

]
  })
</SCRIPT>
现在我改成AJAX的,
$(document).ready(function () {
  $.ajax({
  url: "Function/ChangePic.ashx",
  data: { "val": "index" },
  type: "get",
  datatype: "json",
  success: function (list) {

  var dataobj = eval("(" + list + ")");
  var html = "[";
  var row = 0;
  $.each(dataobj.count, function (idx, item) {
  row = item.count;
  });
  $.each(dataobj.pics, function (idx, item) {
  html += "{src:\"" + item.src + "\",href:\"" + item.href + "\",alt:\"\",breviary: \"#\",type: \"img\"}";
  if (idx < (row - 1)) {
  html += ",";
  }
  });
  html += "]";
  $("#slide").jdSlide({
  width: 766,
  height: 250,
  pics: html
  });
  }
  });
});

就是没用,页面显示 一个src未定义,href未定义

------解决方案--------------------
确定json对象里有href和src这两个属性么?
------解决方案--------------------
浏览器调试一下,看一下返回的数据。
------解决方案--------------------
结构中src接收参数是数组,所以你最好定义html就用var html=[],然后push对象,或者如果保持拼接字符串的话最后eval下。
------解决方案--------------------
探讨

引用:

确定json对象里有href和src这两个属性么?