Javascript 动态更改位置 $(文档).ready(函数(){ //$(“#加载程序”).hide(); $('.player1').livequery('change',function(){ $(this.nextAll('.parent').remove(); $(this.nextAll('label').remove(); $('#characters1').empty(); $('#characters1')。附加(''); $.post(“get_characters.php”{ player_id:$(this.val(), 播放器:$(this.attr('player'), },功能(回应){ setTimeout(“finishAjax('characters1','”+转义(响应)+'”),400); }); 返回false; }); 函数finishAjax(id,响应){ $(“#加载程序”).remove(); $('#'+id).append(unescape(response)); }

Javascript 动态更改位置 $(文档).ready(函数(){ //$(“#加载程序”).hide(); $('.player1').livequery('change',function(){ $(this.nextAll('.parent').remove(); $(this.nextAll('label').remove(); $('#characters1').empty(); $('#characters1')。附加(''); $.post(“get_characters.php”{ player_id:$(this.val(), 播放器:$(this.attr('player'), },功能(回应){ setTimeout(“finishAjax('characters1','”+转义(响应)+'”),400); }); 返回false; }); 函数finishAjax(id,响应){ $(“#加载程序”).remove(); $('#'+id).append(unescape(response)); },javascript,jquery,Javascript,Jquery,好的,我有一个php循环,可以自动创建下拉列表。现在我有了Javascript,可以根据上一个下拉列表的选择动态更新另一个下拉列表。现在是我的问题,php中有25对下拉列表,它们是用id为“player”的唯一下拉列表创建的,并使用一个关于更改的下拉列表。现在我希望javascript能够解释哪个id是哪个,以便它只修改链接到它的id。我可以通过使用适当的id编写25次脚本来实现这一点,但这似乎是对代码的浪费。有没有类似于php的while函数的方法?谢谢提前!任何控制台错误??我建议更改set

好的,我有一个php循环,可以自动创建下拉列表。现在我有了Javascript,可以根据上一个下拉列表的选择动态更新另一个下拉列表。现在是我的问题,php中有25对下拉列表,它们是用id为“player”的唯一下拉列表创建的,并使用一个关于更改的下拉列表。现在我希望javascript能够解释哪个id是哪个,以便它只修改链接到它的id。我可以通过使用适当的id编写25次脚本来实现这一点,但这似乎是对代码的浪费。有没有类似于php的while函数的方法?谢谢提前!

任何控制台错误??我建议更改setTimeout(“finishAjax('characters1','“+escape(response)+””),400);更改为setTimeout(finishAjax('characters1',escape(response)),400);
    $(document).ready(function() {

    //$('#loader').hide();

    $('.player1').livequery('change', function() {

        $(this).nextAll('.parent').remove();
        $(this).nextAll('label').remove();
        $('#characters1').empty();

        $('#characters1').append('<img src="loader.gif" style="float:left; margin-top:7px;" id="loader" alt="" />');
        $.post("get_characters.php", {
            player_id: $(this).val(),
            player: $(this).attr('player'),
        }, function(response){

            setTimeout("finishAjax('characters1', '"+escape(response)+"')", 400);
        });

        return false;
    });
function finishAjax(id, response){
  $('#loader').remove();

  $('#'+id).append(unescape(response));
}