Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jQuery快速鼠标移动mouseleave事件在上一个事件完成之前触发_Php_Jquery_Ajax - Fatal编程技术网

Php jQuery快速鼠标移动mouseleave事件在上一个事件完成之前触发

Php jQuery快速鼠标移动mouseleave事件在上一个事件完成之前触发,php,jquery,ajax,Php,Jquery,Ajax,如果用户将鼠标移到表格单元格上,则下拉框将用通过post调用加载的数据替换html。如果用户的鼠标移动速度不是太快,那么这种方法很好,但是如果移动速度太快,html不会更新,因此当用户将鼠标移回html时,html是不正确的 $(".edit_dropdown").bind('mouseenter', function () { $(this).unbind('mouseenter'); var a = $.trim($(this).html()); var id = $(this).attr(

如果用户将鼠标移到表格单元格上,则下拉框将用通过post调用加载的数据替换html。如果用户的鼠标移动速度不是太快,那么这种方法很好,但是如果移动速度太快,html不会更新,因此当用户将鼠标移回html时,html是不正确的

$(".edit_dropdown").bind('mouseenter', function () {
$(this).unbind('mouseenter');
var a = $.trim($(this).html());
var id = $(this).attr('id');

$(this).html("<span id='s-" + id + "'></span>");
$.post('save/dropdown.php', {
    id: id,
    a: a
}, function (data) {
    $("#s-" + id).html(data);

    $(".edit_dropdown").bind('mouseleave', function () {
        var id = $(this).attr('id');
        var a = $("#e-" + id).val();
        var dir = $(this).attr('class');
        $(this).html(a);
        $(this).bind('mouseenter', function () {
            $(this).unbind('mouseenter');
            var a = $.trim($(this).html());
            var id = $(this).attr('id');
            $(this).html("<span id='s-" + id + "'></span>");
            $.post('save/dropdown.php', {
                id: id,
                a: a
            }, function (data) {
                $("#s-" + id).html(data);
            });
        });

    });
});
}); 
$(“.edit_下拉列表”).bind('mouseenter',function(){
$(this.unbind('mouseenter');
var a=$.trim($(this.html());
var id=$(this.attr('id');
$(this.html(“”);
$.post('save/dropdown.php'{
id:id,
a:a
},函数(数据){
$(#s-“+id).html(数据);
$(“.edit_下拉列表”).bind('mouseleave',function(){
var id=$(this.attr('id');
var a=$(“#e-”+id).val();
var dir=$(this.attr('class');
$(this.html(a);
$(this.bind('mouseenter',function(){
$(this.unbind('mouseenter');
var a=$.trim($(this.html());
var id=$(this.attr('id');
$(this.html(“”);
$.post('save/dropdown.php'{
id:id,
a:a
},函数(数据){
$(#s-“+id).html(数据);
});
});
});
});
}); 
html


客户县

$.post文件返回一个UK县列表,如果县名称与html匹配,则该县将作为所选选项返回。

出现此问题的原因是mouseleave处理程序仅在响应对mouseenter处理程序的异步响应时放置到位

您应该寻找一种更简单的总体代码结构,它不涉及分离和重新连接处理程序

应该可以编写两个保持永久连接的处理程序,如下所示:

$(".edit_dropdown").on('mouseenter', function () {
    //Perform all mouseenter actions here.
    //If necessary, test for different states and branch as required.
}).on('mouseleave', function () {
    //Perform all mouseleave actions here.
    //If necessary, test for different states and branch as required.
});

另一点:由于县列表是静态的,因此可以将其作为页面原始HTML的一部分提供一次。然后,您只需要返回要选择的县的名称或id,而不是重复返回整个列表。

您可以创建一个小提琴,以便我们测试问题吗?感谢提供的信息,.on使脚本更加简单,不幸的是,如果鼠标移动太快,MouseenterHTML更改在鼠标移动之前不会完成。有没有延迟鼠标器?AHA,这就是为什么我建议你考虑不同状态的测试,并根据需要进行分支。如果mouseover的ajax尚未响应,我希望您需要以不同的方式处理mouseleave。我很难说清楚,因为我不完全理解你想要实现什么。感谢你的回答,我试图实现的是在一个用户可以查看客户详细信息的表格上,如果他们将鼠标悬停在单元格上,那么文本将变成一个文本框或下拉列表,具体取决于单元格数据,这在文本框上可以很好地工作,我遇到的问题是,当编辑需要是一个下拉列表时,文本会变成一个下拉列表,并选择与单元格html相同的值。发生了什么?如果鼠标移动过快,则mouseenter调用没有时间在下拉列表中获取所选项目,因此无法将其作为新的html进行传递。我不理解的是(a)mouseleave和(b)上发生了什么mouseleave上应该发生什么。使用hoverIntent插件,我已经做了相当于延迟mouseleave调用的操作,这允许html有时间传递到单元格。我想,这将取决于互联网连接速度,这将是如何成功地与大量的邮政数据。谢谢你的帮助
$(".edit_dropdown").on('mouseenter', function () {
    //Perform all mouseenter actions here.
    //If necessary, test for different states and branch as required.
}).on('mouseleave', function () {
    //Perform all mouseleave actions here.
    //If necessary, test for different states and branch as required.
});