【问题标题】:How can I add html tags in Javascript: var quotes = new Array("tags html here")如何在 Javascript 中添加 html 标签:var quotes = new Array("tags html here")
【发布时间】:2014-12-07 01:46:43
【问题描述】:

您好,我尝试在代码的“数组”中添加 html 标签,您能帮帮我吗?

$(document).ready(function() {
    var quotes = new Array("exemple exemple","exemple...");
    var randno = Math.floor(Math.random()*(quotes.length));
    $('.quote').append(quotes[randno]);
    console.log(randno);
}

【问题讨论】:

  • 你还没有指定任何问题。
  • 问题一点都不清楚。是否要将 php 数组传递给 javascript?

标签: javascript jquery arrays quotes


【解决方案1】:

简单地将你想要的标签写入数组(并在标签中使用'作为引号)

....
var quotes = new Array("<li>bla</li>","<a href='http://www.google.com'>link</a>");

....
var quotes = new Array();
quotes.push("<li>asdf</li>");

【讨论】:

  • HTML 标签未增强,以纯文本形式出现
  • 你的'.quote'是什么类型的元素?
  • var quotes = new Array("« L'amitié du chien est sans Competitione plus vive et plus constante que celle de l'homme »(Montaigne)","Other text...");
  • 不是数组。我的意思是你附加数组值的元素 ($('.quote'))
  • 对不起,您不是说要在数组中添加 HTML 标记吗?!?我给你的代码有效。
猜你喜欢
  • 2020-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-26
  • 2019-08-06
  • 1970-01-01
相关资源
最近更新 更多