【问题标题】:How to get the text of <a> tag with MeteorJS? [duplicate]如何使用 MeteorJS 获取 <a> 标签的文本? [复制]
【发布时间】:2017-05-22 20:10:09
【问题描述】:

我关注了一些 StackOverflow 问题,例如 Getting the text of a <a> tag,但我仍然无法收到我的文本。

for (i = 0; i < 5; i++) { 
var ul = document.getElementById('listExisting');
var li = document.createElement("li");
var a = document.createElement("a");
a.setAttribute("href", "#");
a.setAttribute("class", "oneExistingFile");       a.appendChild(document.createTextNode("example"+i))
li.appendChild(a);
ul.appendChild(li);
}

$(document).ready(function() {
  $('.oneExistingFile').click(function() {
    console.log(this.textContent)
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="dropdown-menu" id="listExisting">
</ul>

在这里它可以工作,但在我的代码中我有undefined,尽管它实际上是相同的结构

我做错了什么?

我的听众是这样的流星:

  'click .oneExistingFile': function(event, template){
    console.log(this.textContent);
  }

【问题讨论】:

  • this.textContent 似乎可以很好地理解文本。
  • @JJJ 好像不在这里
  • 好吧,我们无法真正说出为什么它在您的代码中不起作用。你必须想出一个复制问题的演示。
  • @JJJ 我不能提供更多,我添加了我的 MeteorJS 方法
  • 为什么这被标记为流星?

标签: javascript jquery meteor onclick


【解决方案1】:

这个怎么样?

'click .oneExistingFile': function(event, template){
    console.log(event.target.text);
  }

【讨论】:

  • 它也可以 :) 谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多