使用javascript插入rel属性
insert rel attribute with javascript
我有这个函数:
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属性。关于如何使这项工作发挥作用,有什么建议吗?
由于您已经在使用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');
}
相关文章:
- Jquery将data-rel属性添加到所有输入字段,并移除name属性
- 如何在 Tinnymce 编辑器的插入链接弹出窗口中添加 rel 属性
- 如何在 javascript 生成的表上使用“rel”属性
- 使用 Jquery .each 获取 rel 属性
- 从标记中删除 rel 属性
- 按 rel 属性对元素进行分组
- 定位 AJAX 会通过使用“rel”属性生成正确的 DIV
- 如何使用链接的行 id 和 rel 属性将 onclick 事件指向特定的表行内容 - jQuery
- window.open()添加一个rel="nofollow”;属性
- 如何在锚点的rel属性中传递java脚本变量的值
- 如何在FullCalendar中为每个事件添加rel属性
- 使用javascript插入rel属性
- 动态加载 rel 属性中的链接
- 根据rel属性移除锚点(后退按钮)
- 当bxslider加载时,Colorbox在rel属性上断开
- 如何在使用value和rel属性更改选项元素时检查复选框
- 使用使用rel属性显示的模式编辑gridview单元格
- jQuery中的Rel属性
- 行为'rel'属性:prop() vs attr()
- number = parseInt(number);需要从rel属性中生成非数字