gpt4 book ai didi

javascript在循环内悬停href时获取参数

转载 作者:行者123 更新时间:2023-12-01 14:36:36 24 4
gpt4 key购买 nike

我有以下问题:

var xmlhttp = new getXMLObject();   //xmlhttp holds the ajax object

$(function() {
$('a.popper').hover(function(e) {


if(xmlhttp) {

xmlhttp.open("GET","DokterWeek_KlantoverzichtServlet?" + $("a.popper").prop("href").split("?")[1],true);//gettime will be the servlet name
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(null);
}

在上面您可以看到,当我将鼠标悬停在有效的 a href class="popper"上时,我获取了 servlet 的参数。但问题是它总是在 foreach 循环中获取最后一个“a href”参数...

 <c:forEach items="${row}" var="cell">

<a href="./DokterWeek_KlantoverzichtServlet?AfspraakID=${cell.afspraakId}&Id=${cell.id}&KlantId=${cell.klant.id}"
class="popper" data-popbox="pop1">

<c:forEach items="${row}" var="cell">

是否有任何 javascript 或 jquery 可能性,当我将鼠标悬停在其上时,我可以实时获取 a href 值...当我将鼠标悬停在这些链接上时,我的浏览器会看到参数发生变化,但 javascript 不会获取它.. Javascript获取循环中的第一个或最后一个 ahref...

请帮助我,我已经寻找解决方案超过两天了:(

最佳答案

问题是您没有获得悬停元素的 href 值。您可以使用 $(this) 来做到这一点。在您的情况下,您使用 $("a.popper"),它获取所有 a.popper 元素,从而选择最后一个 href。

就您而言:

var xmlhttp = new getXMLObject();   //xmlhttp holds the ajax object

$(function() {
$('a.popper').hover(function(e) {
var theElementYourHovering = $(this),
currentHref = theElementYourHovering.attr('href');

// Do your stuff here
}

关于javascript在循环内悬停href时获取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16438904/

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