【问题标题】:Get href or text attriburlte and place it in input filed获取 href 或 text 属性并将其放在输入字段中
【发布时间】:2018-05-11 08:15:16
【问题描述】:

我已经搜索了很多主题,所有这些主题都是逆序的,然后是我需要的。

我有一个带有输入字段的表单,我想获取特定类的链接并将其 href 属性放在输入框中。它可以是href,也可以是标签的文本。

如何做到这一点?

【问题讨论】:

标签: jquery url input


【解决方案1】:

使用attr 方法。

标记

<input type="text" id="hrefHere" />
<a href="http://www.google.com" class="google">Google Link</a>  

jQuery

var hrefValue = $(".google").attr("href");
$("#hrefHere").val(hrefValue);

【讨论】:

  • 谢谢!它可以工作,但你写的引用引起了一些问题,所以我不得不替换它们。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-25
  • 2017-12-06
相关资源
最近更新 更多