I am trying to get the text within
<li><a href="">Navi</a><li>
back using Javascript.
var clickedTopPlayer = function()
{
var player = this.innerHTML;
var parsed = player.innerHTML();
loadResults(parsed);
return false;
};
$('li').on("click", clickedTopPlayer);
The code I tried to do this with wouldn't work. Any ideas?
答案 0 :(得分:0)
只需使用innerText
属性:
var clickedTopPlayer = function() {
var player = this.innerText;
loadResults(player);
return false;
};
$('li').on("click", clickedTopPlayer);
见这里:
var clickedTopPlayer = function() {
var player = this.innerText;
console.log(player);
};
$('li').on("click", clickedTopPlayer);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a>Foo</a>
</li>
&#13;
另请注意,innerHTML
永远不是一个函数 - 正如您在此处使用它一样
var parsed = player.innerHTML();