gpt4 book ai didi

jquery - 为什么jquery select加载循环

转载 作者:行者123 更新时间:2023-12-01 04:31:43 25 4
gpt4 key购买 nike

我不明白为什么每次更改都会多次提醒我......

    $(function(){
$("#shift_name_<?php print $shift_id;?>").change(function () {
$(".alertmessage").load("messages.php?eid="+$("#shift_name_<?php print $shift_id;?>").val(), function(data<?php print $shift_id;?>) {
if(data<?php print $shift_id;?>!=''){
alert(data<?php print $shift_id;?>);
}
});
});
});

基本上,有一些是循环遍历的,并根据 php 变量给出特定的 id。但是,当我更改一个时,它会提醒我 x 次,其中 x 是页面上存在的数量...

最佳答案

你有多个“alertmessage”div吗?如果是这样,您将加载所有这些内容,而不仅仅是一个。就我个人而言,我不会这样做。相反,请尝试:

<select name="..." id="shift13" class="alert">
...
</select>
<div id="alert13" class="alertmessage shift13"></div>

与:

$(function() {
$("select.alert").change(function() {
$("div.alertmessage." + this.id).load("messages.php",
{id: this.id}, function() {
alert(this.id); // alert13
});
});
});

(恕我直言)是比循环和创建重复事件处理程序更干净的解决方案。基本上,将您需要的信息编码在元素中。在上面,组合框的 ID 提供了 AJAX 调用的 ID,并将其链接到要加载的相关 DIV。

关于jquery - 为什么jquery select加载循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1934702/

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