gpt4 book ai didi

javascript 下拉菜单 - 在选择时转到 url

转载 作者:行者123 更新时间:2023-11-29 18:25:39 25 4
gpt4 key购买 nike

我正在使用 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

最佳答案

有点快速和肮脏,但你可以为你传递的对象添加额外的属性:

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;
}
});​

关于javascript 下拉菜单 - 在选择时转到 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13612277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com