gpt4 book ai didi

javascript - 如何从特定元素中获取值(value)?

转载 作者:行者123 更新时间:2023-12-03 04:30:44 24 4
gpt4 key购买 nike

当单击具有 id="username" 的特定链接时,我需要获取值,但它不起作用...

我的尝试:

function rev() {
var username = (this).getElementById("username").textContent;
return alert (username);
}
while($trackResultRow = mysqli_fetch_assoc($trackResult)){?>

<a onclick="rev()"><span class="glyphicon glyphicon-thumbs-down pull-right"></span></a>
<span class="glyphicon glyphicon-thumbs-up pull-right"></span>
<li>
<a href="<?php echo $trackResultRow['track_path']?>"><span id="username"><?php echo $trackResultRow['username']?></span> - <span id="track"><?php echo $trackResultRow['track_name']?></span>

<span class="glyphicon glyphicon-download pull-right"></span>
<div class="pull-right">
<span class="glyphicon glyphicon-pause pull-right" onclick="document.getElementById('aud').pause()"></span>
<span class="glyphicon glyphicon-play pull-right" onclick="document.getElementById('aud').play()"></span>
</div>
</a>
</li>
<hr>
<?php
}
?>

我也尝试过

function rev() {
var username = document.getElementById(value).textContent;

return alert (username);
}


<button id="but" onclick="rev()">hey</button>
<button id="but" onclick="rev()">hey233</button>

有什么想法吗?

最佳答案

如果您想定位页面上的某个元素,请使用document.getElementById

document.getElementById("username").textContent;

关于javascript - 如何从特定元素中获取值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43501759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com