【问题标题】:Get Anchor Tag from textarea using jquery使用 jquery 从 textarea 获取锚标记
【发布时间】:2014-12-10 12:16:59
【问题描述】:

我有一个文本区域,其中包含锚标记形式的链接列表及其内部内容 例如

<a href="http://example1.com/azaz" class="tex1"> Example 1</a>
<a href="http://example1.com/aza" class="tex1"> Example 2</a>
<a href="http://example1.com/za" class="tex2"> Example 3</a>
<a href="http://example1.com/az" class="tex2"> Example 4</a>

以上信息在文本区域内给出。我想在单击提交后我想检索特定类的所有锚标记的 href 部分,如 tex1。 例如我想要像

这样的输出

http://example1.com/azaz
http://example1.com/aza

我如何使用 Jquery/javascript 实现这一目标

【问题讨论】:

  • ID 应该是唯一的。

标签: javascript jquery html css


【解决方案1】:

试试这个

var text = $("textarea").val();

var res = $(text).map(function() { 

       return $(this).attr("href");
});

console.log(res);

FIDDLE

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 2021-03-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多