gpt4 book ai didi

php - #id $(this) 的 child

转载 作者:行者123 更新时间:2023-11-30 13:25:29 25 4
gpt4 key购买 nike

对于凌乱的脚本和标签,我深表歉意,我只是一个初学者。我想在类为“reserveAPickupAppointmentLocation”的 div 中选择文本。这个 div 在 $(this) 里面。$(this) 是从许多条目中选择的条目。相关的行是:

var location = $(".reserveAPickupAppointmentLocation, this").text();

这会返回所有条目的位置,而不仅仅是 $(this)。我如何才能只得到我想要的?

完整的 jquery 函数:

   $(".reserveAPickupAppointmentRoommateAppointment").click (function() {
if ($(this).hasClass("confirm")) {
}
else {
$("img").remove(".confirmAppointment");
$(".reserveAPickupAppointmentRoommateAppointment").removeClass("confirm");
$(this).addClass("confirm");
$(this).append("<img src=images/confirmAppointment.png class=confirmAppointment id=roommateAppointment>");
$(".confirmAppointment").click (function() {
$(".confirmAppointment").unbind("click");
var location = $(".reserveAPickupAppointmentLocation, this").text();
alert (location);
});
}
});

相关的php部分

echo '<table>';
while ($row = mysql_fetch_array($result)) {

echo
'<tbody class = "reserveAPickupAppointmentRoommateAppointment">
<tr>
<td>'
.$row["name"].
'</td>
<td>
<span class = "reserveAPickupAppointmentLocation">'
.$row["location"].
'</span>
</td>
<td>
<span class = "reserveAPickupAppointmentSubLocation">'
.$row["subLocation"].
'</span>
</td>
</tr>
<tr>
<td>
<span class = "reserveAPickupAppointmentStartTime">'
.$row["startTime"].
'</span> -
<span class = "reserveAPickupAppointmentEndTime">'
.$row["endTime"].
'</span>
</td>
<td>
<span class = "reserveAPickupAppointmentDate">'
.$row["date"].
'</span>
</td>
</tr>
</tbody>';
}

echo '</table>

最佳答案

要将第二个参数传递给 jQuery 选择器作为搜索的上下文,您需要先关闭引号。

var location = $(".reserveAPickupAppointmentLocation", this).text();

但是

点击回调中this的值会改变,所以你需要事先保存它。

$(this).append("<img src=images/confirmAppointment.png class=confirmAppointment id=roommateAppointment>");
var self = this;
$(".confirmAppointment").click (function() {
$(".confirmAppointment").unbind("click");
var location = $(".reserveAPickupAppointmentLocation", self).text();
alert (location);
});

关于php - #id $(this) 的 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8622489/

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