Jquery fancybox中的Attr
我尝试在Fancybox中获取我的属性,当我使用href时获取,但如果我尝试获取我的属性,则只会得到“未定义”Jquery fancybox中的Attr,jquery,fancybox,Jquery,Fancybox,我尝试在Fancybox中获取我的属性,当我使用href时获取,但如果我尝试获取我的属性,则只会得到“未定义” 函数formatTitle(标题、currentArray、currentIndex、currentOpts){ 变量titlenormal=“”+ '' + ''+标题+''; 警报($(this.attr(“href”)); 返回滴定标准; } 如果在类似fancybox的内部设置选项标题格式 $(".fancybox").fancybox({ 'titleFormat': f
函数formatTitle(标题、currentArray、currentIndex、currentOpts){
变量titlenormal=“”+
'' +
''+标题+'';
警报($(this.attr(“href”));
返回滴定标准;
}
如果在类似fancybox的内部设置选项标题格式
$(".fancybox").fancybox({
'titleFormat': formatTitle
});
然后,您的函数formatTitle
工作并提醒href
属性值
您也可以改用this.href
编辑:2012年3月23日-太平洋时间下午12:30回应评论
我猜您还不够清楚,无法指定要获取哪个属性
无论如何,alert($(this.attr(“href”)
之所以有效,是因为此时,href
是fancybox函数中的jQuery对象,而private
不是
作为解决方法,请尝试以下方法:
alert($(".grouped_elements").eq(currentIndex).attr('private'));
在formatTitle
函数中,如下所示:
function formatTitle(title, currentArray, currentIndex, currentOpts) {
var titlenormal = '<input type="hidden" id="idPhoto" value="' + currentArray[currentIndex].id + '">' +
'<span id="fancybox-title-over">' +
'<div id="boxComment" style="position:relative;"><div style="white-space: nowrap;"><div style="float: left;">este es ' + title + '</div><div id="star" style="width:100%"> </div></div>';
alert($(".grouped_elements").eq(currentIndex).attr('private'));
return titlenormal;
}
如果您在fancybox中设置选项
titleFormat
,就像
$(".fancybox").fancybox({
'titleFormat': formatTitle
});
然后,您的函数formatTitle
工作并提醒href
属性值
您也可以改用this.href
编辑:2012年3月23日-太平洋时间下午12:30回应评论
我猜您还不够清楚,无法指定要获取哪个属性
无论如何,alert($(this.attr(“href”)
之所以有效,是因为此时,href
是fancybox函数中的jQuery对象,而private
不是
作为解决方法,请尝试以下方法:
alert($(".grouped_elements").eq(currentIndex).attr('private'));
在formatTitle
函数中,如下所示:
function formatTitle(title, currentArray, currentIndex, currentOpts) {
var titlenormal = '<input type="hidden" id="idPhoto" value="' + currentArray[currentIndex].id + '">' +
'<span id="fancybox-title-over">' +
'<div id="boxComment" style="position:relative;"><div style="white-space: nowrap;"><div style="float: left;">este es ' + title + '</div><div id="star" style="width:100%"> </div></div>';
alert($(".grouped_elements").eq(currentIndex).attr('private'));
return titlenormal;
}
警报工作得很好,这只是一个测试。我需要在我的标签中获得私有属性。警报工作得很好,这只是一个测试。我需要在标记A中获取私有属性