我试图使用ddslick(http://designwithpc.com/plugins/ddslick) 我的代码:
<script>
$('#demoBasic').ddslick({
var ddData = [{
text: "Facebook",
value: 1,
selected: false,
description: "Description with Facebook",
imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
}, {
text: "Twitter",
value: 2,
selected: false,
description: "Description with Twitter",
imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
}, {
text: "LinkedIn",
value: 3,
selected: true,
description: "Description with LinkedIn",
imageSrc: "http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png"
}, {
text: "Foursquare",
value: 4,
selected: false,
description: "Description with Foursquare",
imageSrc: "http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png"
}];
data: ddData,
width: 300,
imagePosition: "left",
selectText: "Select your favorite social network",
onSelected: function(data) {
console.log(data);
}
});
</script>
但是我收到了错误:
Uncaught SyntaxError: Unexpected identifier
我如何处理这个问题? 我使用的是JQuery 1.11.2
答案 0 :(得分:1)
您的对象定义错误:
$('#demoBasic').ddslick({
var ddData = [{
应为:
$('#demoBasic').ddslick({
ddData : [{
(对象定义中var
没有用途)
也 在对象定义的中间有一个分号。
}];
应该是:
}],
最后但并非最不重要的是,无需像您一样定义ddata
,因为您可以直接将其放入data
<script>
$('#demoBasic').ddslick({
data: [{
text: "Facebook",
value: 1,
selected: false,
description: "Description with Facebook",
imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
}, {
text: "Twitter",
value: 2,
selected: false,
description: "Description with Twitter",
imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
}, {
text: "LinkedIn",
value: 3,
selected: true,
description: "Description with LinkedIn",
imageSrc: "http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png"
}, {
text: "Foursquare",
value: 4,
selected: false,
description: "Description with Foursquare",
imageSrc: "http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png"
}],
width: 300,
imagePosition: "left",
selectText: "Select your favorite social network",
onSelected: function(data) {
console.log(data);
}
});
</script>