[英]jQuery Adding <a href=“#”
我有以下當前返回<li>
代碼段。 如何使它返回<li><a href="#"
我將不會使用href
但正在使用Boostrap3,因此導航時需要它。
碼:
fetchJSON.done(function(response) {
var buttons = response.map(function(i) {
return $('<li>', {
text: i.title,
"data-author": i.author,
"data-body": i.body
})
});
$('ul').append(buttons);
一樣容易
return $('<li>', {
"data-author": i.author,
"data-body": i.body
}).append($('<a>', { href: '#', text: i.title }))
我還建議您使用:
.data({
author: i.author,
body: i.body
})
而不是手工制作
您必須能夠直接使用append方法
.append("<a href='#'>some Description</a>");
return $('<li>', {
text: i.title,
"data-author": i.author,
"data-body": i.body
}).append("<a href='#'>some Description</a>");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.