javascript - 使用 jquery 从 textarea 获取 anchor 标签

标签 javascript jquery html css

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

<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>

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

这样的输出

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

我如何使用 Jquery/javascript 实现此目的

最佳答案

试试这个

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

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

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

console.log(res);

FIDDLE

关于javascript - 使用 jquery 从 textarea 获取 anchor 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27400800/

相关文章:

javascript - fs.readdir 首先同步目录

html - 你能在 SASS/SCSS CSS 中使用多个条件吗

javascript - 获取对表的 td 输入的 Ajax 响应

html - 网页在移动设备上开始放大

javascript - querySelectorAll 使用两个或多个数据集作为查询

javascript - 为什么 ToSimplifyText 保持不变?

javascript - 强制 div 高度为最接近背景图像高度的倍数

jquery - jQuery 中最快的 children() 或 find() 是什么?

jquery - 交叉淡入淡出图像javascript

jquery - 如何为 yui 和 jQuery 数据表维护相同的 css 样式