0
 jQuery.ajaxSettings.traditional = true;
 $(document).ready(function(){
        $(".wijstoe").change(function(){
            var id = $(this).children('#test').map(function() {
             return $(this).text();
            }).get();
            var mw = $("option").val();
            var opg = "Opgeslagen !";
            $("#loading").css("display","block");
            $.post("wijstoe.php",
                {mw:mw, id:id},
                function(data,status)
                {       
                    $("#loading").css("display","none");
                    $(this).children('#tester').html(opg);                                          
                });
        });
    });

HTML / PHP:

                        echo "<td>$row[2]</td>";
                        echo "<td id='test1'>";
                        echo "<div class='wijstoe'>";
                        echo "<div id='test' style='display:none;'>".$row[0]."</div>";
                        echo "<form><select>";
                        if($_SESSION['uname'] == 'admin') {
                            $querya="select uname from users";
                            $resulta = mysql_query($querya);
                            while ($rowa = mysql_fetch_row($resulta)) {
                            echo "<option>".$rowa[0]."</option>";
                                    }
                        echo "</select></form>";
                        echo "<div id='tester'>DIDI</div>";
                        echo "</div>";
                        echo "</td>";
                        }

这不会将来自 id tester (DIDI) 的文本替换为文本 opgeslagen。

当我不使用 $(this) 它可以工作,但它适用于每个带有 id tester 的 div,我只希望这个特定的 div 替换文本。

所以这有效:

  $(this).children('#tester').html(opg);          

这不起作用:

  $('#tester').html(opg);          
4

2 回答 2

1
        $.post("wijstoe.php",
            {mw:mw, id:id},
            function(data,status)
            {       
                $("#loading").css("display","none");
                $(this).children('#tester').html(opg);                                          
            });

列出位置的 $(this) 将是 POST 方法。

拥有多个具有相同 ID 的元素并不是一个好习惯。在多个元素上使用时更改为类。

var tester = $(this).find('.tester');

$.post("wijstoe.php",
     {mw:mw, id:id},
     function(data,status)
     {       
         $("#loading").css("display","none");
         $(tester).html(opg);                                          
     });
于 2013-09-06T15:49:57.527 回答
0

尝试

$(this).find('#tester').html(opg);    
于 2013-09-06T15:45:29.573 回答