在javascript事件中链接

时间:2015-10-02 05:35:04

标签: javascript events hyperlink calendar

我有一个日历事件列表。我想将标题或位置超链接 - 但最好是位置(见下文)到网站。我该怎么做?

var events = [
{ date: "2015-10-10", title: 'October 15, 2015', location: 'Event One Deadline' }, 
{ date: "2015-10-25", title: 'October 25, 2015', 'location: 'Payment Deadline' },
{ date: "2015-12-25", title: 'December 25, 2015', location: 'Christmas: We're closed.' },
{ date: "2015-12-26",    title: 'December 26, 2015', location: 'Boxing Day: We're closed.'}  ];

2 个答案:

答案 0 :(得分:0)

如果我做得对,你想改变位置数据,使其成为一个链接,所以你走了:

events.map(function( row,index ){

     row.location = '<a href="#">' + row.location + '</a>';

});

或旧方式

for( var i = 0, length = events.length; i < length; i++ ) {

     events[i].location = '<a href="#">' + events[i].location + '</a>';

}

答案 1 :(得分:0)

如果我有你的问题,你需要解析JSON数据。 您的代码是JSON对象
您可以使用jSON.parse(JSON_DATA)

&#13;
&#13;
var events = [
{ date: "2015-10-10", title: "October 15, 2015", location: "Event One Deadline" }, 
{ date: "2015-10-25", title: "October 25, 2015", location: "Payment Deadline" },
{ date: "2015-12-25", title: "December 25, 2015", location: "Christmas: We're closed." },
{ date: "2015-12-26",    title: "December 26, 2015", location: "Boxing Day: We're closed."}  ];
 console.log(events); // Object
for(i=0;i<=events.length;i++){
  console.log(events[i].date);
  console.log(events[i].location);
  console.log(events[i].title);
  }
&#13;
&#13;
&#13;

现在值可用于制作链接
注意:您的JSON数据需要有双qutos(&#34;&#34; ),而不是&#39;&#39;
< / p>

您现在可以访问以下值:events[0].title并创建如下链接: 事件[0] .location