0

我有这个功能:

 if (location.locationUrl != '') {
content += "<a class='viewLocationPage btn corePrettyStyle'  " +   
(mapObject.options.openinnew == false ? "" : "target='_blank'") +  
" href='" + location.locationUrl + "' >View location detail</a>";
        }

我添加了这样的rel属性:

if (location.locationUrl != '') {
            content += "<a class='viewLocationPage btn corePrettyStyle'  " + 
            (mapObject.options.openinnew == false ? "" : "target='_blank'") +
            "rel='prettyPhoto[iframes]'" + " href='" + location.locationUrl + "' >View location detail</a>";
        }

但不起作用,它不会在标记中添加任何 rel 属性。关于如何使这项工作的任何建议?

4

1 回答 1

1

由于您已经在使用 jQuery,因此使用 jQuery 构造函数创建元素会更容易:

if (location.locationUrl != '') {
    $('<a>', {
        'class': 'viewLocationPage btn corePrettyStyle',
        target: mapObject.options.openinnew ? '_blank' : '',
        rel: 'prettyPhoto[iframes]',
        href: location.locationUrl,
        text: 'View location detail'
    }).appendTo('#selector');
}
于 2013-06-21T18:17:35.237 回答