我正在使用jqueryui自动填充,并使用ContentFlow设置了对图库的搜索,当找到图像时,会显示一个小图标,用户可以使用灯箱打开图像(prettyphoto)< / p>
以下是代码:
$(function() {
var projects = [
{
value: "Alcatraz",
label: "Alcatraz",
icon: "Alcatraz.jpg",
url: "slides/Alcatraz.jpg",
desc: "",
imgN: "1"
},
{
value: "Amber Light",
label: "Amber Light",
icon: "Amber Light.jpg",
url: "slides/Amber%20Light.jpg",
desc: "",
imgN: "2"
},
{
value: "Blue Boat",
label: "Blue Boat",
icon: "Blue Boat.jpg",
url: "slides/Blue%20Boat.jpg",
desc: "",
imgN: "3"
}
];
$( "#project" ).autocomplete({
minLength: 0,
source: projects,
focus: function( event, ui ) {
$( "#project" ).val( ui.item.label );
return false;
},
select: function( event, ui ) {
$( "#project" ).val( ui.item.label );
$( "#project-id" ).val( ui.item.value );
$( "#project-icon" ).attr( "src", "thumbs/" + ui.item.icon );
$( "#project-description" ).html( ui.item.desc );
$( "#project-label" ).html( ui.item.label );
$( "#project-link" ).attr("href", ui.item.url );
$( "#project-link" ).attr("title", ui.item.label );
return false;
},
close: function() {
var value = $( "#project" ).val( ui.item.imgN );
cf.moveTo(value);
}
})
.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + " - " + item.desc + "</a>" )
.appendTo( ul );
};
});
HTML:
<div id="project-label">Search</div>
<a href="#" rel="prettyPhoto" class="" id="project-link"><img id="project-icon" src="res/transparent_1x1.png"/></a>
<input id="project"/>
<input type="hidden" id="project-id"/>
<p id="project-label"></p>
<p id="project-description"></p>
我遇到的问题是使用以下功能:
close: function() {
var value = $( "#project" ).val( ui.item.imgN );
cf.moveTo(value);
}
我需要图片库使用
滚动到内容流中的特定图片 cf.moveTo();
我没有让我的代码返回此值。任何帮助将不胜感激。
答案 0 :(得分:1)
使用val()时,不应输入用于设置值的参数,只需要在想要值的元素上调用val()。
尝试:
var value = $( "#project "+ui+"."+item+"."+imgN).val();
或类似的东西。
答案 1 :(得分:1)
经过试验和磨难,我找到了一种方法来使用这个额外的修改代码:
select: function( event, ui ) {
$( "#project-imgN" ).val( ui.item.imgN );
return false;
},
close: function(event, ui ) {
function runEffect() {
// get effect type from
var move = $( "#project-imgN" ).val();
// run the effect
cf.moveTo(move);
};
runEffect();
}
})