2

我正在使用ddSlick下拉菜单,因为它也有图像。当您选择一个值时,没有任何反应。如果被选中,我如何将其转到 facebook.com 或 twitter.com?这是代码:

var ddData = [
 {
 text: "Facebook",
 value: "FB",
 description: "Description with Facebook",
 imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
 },
 {
 text: "Twitter",
 value: "TWT",
 description: "Description with Twitter",
 imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
 }
 ];

$('#demoBasic').ddslick({
data: ddData,
width: 300,
imagePosition: "left",
selectText: "Select your favorite social network",
onSelected: function (data) {
console.log(data);
}
});

它使用这些文件:jquery 1.7.2。和 ddslick.js

4

1 回答 1

4

有点快速和肮脏,但您可以向传递的对象添加其他属性:

var ddData = [
 {
     text: "Facebook",
     value: "FB",
     description: "Description with Facebook",
     imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png",
     url:"http://www.facebook.com"
 },
 {
     text: "Twitter",
     value: "TWT",
     description: "Description with Twitter",
     imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png",
     url:"http://www.twitter.com"
 }
 ];

$('#demoBasic').ddslick({
     data: ddData,
     width: 300,
     imagePosition: "left",
     selectText: "Select your favorite social network",
     onSelected: function (data) {
         window.location = data.selectedData.url;
}
});​
于 2012-11-29T09:07:06.613 回答