0

1つのフィールドに1つのオートコンプリートドロップダウンがある場合はすべて正常に機能しますが、さらに多くのフィールドにドロップダウンを追加すると、入力フィールドの値に、呼び出されたphpファイルから返されるliのテキストが入力されなくなります。

以下は、.sugnorm1がliのクラスである場合に機能します

var delay = (function () {
var timer = 0;
return function (callback, ms) {
    clearTimeout(timer);
    timer = setTimeout(callback, ms);
};
})();
$(document).ready(function () {
$('#quality1').bind('input propertychange', function () {
    delay(function () {
        $.post("functions/autocomplete.php", {
            quality:$(this).val(),
            questionname:"<?php echo $_SESSION['question']; ?>",
            count:1
        }, function (response) {
            $('#qualitySuggest1').hide();
            setTimeout("finishAjax('qualitySuggest1', '" + escape(response) + "')", 20);
        });
        return false;
    }, 20);
});
});

$('.sugnorm1').live("mouseover mouseout click", function(event) {
    if ( event.type == "mouseover" ) {
        $(this).addClass('sughover');
    } else if ( event.type == "click") {
        $("#quality1").val($(this).text());
        $("#qualitySuggest1").hide();
    }
    else {
        $(this).removeClass('sughover');
    }
});

$("#quality1").blur(function () {
    $("#qualitySuggest1").hide();
});


});
function finishAjax(id, response) {
$('#' + id).html(unescape(response));
$('#' + id).show();
} //finishAjax

ただし、別のフィールドを追加すると、品質の提案.hide()が呼び出されますが、event.type==クリックして両方のフィールドで機能するアラートなどを取得できません。

var delay = (function () {
var timer = 0;
return function (callback, ms) {
    clearTimeout(timer);
    timer = setTimeout(callback, ms);
};
})();
$(document).ready(function () {
$('#quality1').bind('input propertychange', function () {
    delay(function () {
        $.post("functions/autocomplete.php", {
            quality:$(this).val(),
            questionname:"<?php echo $_SESSION['question']; ?>",
            count:1
        }, function (response) {
            $('#qualitySuggest1').hide();
            setTimeout("finishAjax('qualitySuggest1', '" + escape(response) + "')", 20);
        });
        return false;
    }, 20);
});
$('#quality2').bind('input propertychange', function () {
    delay(function () {
        $.post("functions/autocomplete.php", {
            quality:$(this).val(),
            questionname:"<?php echo $_SESSION['question']; ?>",
            count:2
        }, function (response) {
            $('#qualitySuggest2').hide();
            setTimeout("finishAjax('qualitySuggest2', '" + escape(response) + "')", 20);
        });
        return false;
    }, 20);
});
});

$('.sugnorm1').live("mouseover mouseout click", function(event) {
    if ( event.type == "mouseover" ) {
        $(this).addClass('sughover');
    } else if ( event.type == "click") {
        $("#quality1").val($(this).text());
        $("#qualitySuggest1").hide();
    }
    else {
        $(this).removeClass('sughover');
    }
});

$("#quality1").blur(function () {
    $("#qualitySuggest1").hide();
});

$('.sugnorm2').live("mouseover mouseout click", function(event) {
    if ( event.type == "mouseover" ) {
        $(this).addClass('sughover');
    } else if ( event.type == "click") {
        $("#quality2").val($(this).text());
        $("#qualitySuggest2").hide();
    }
    else {
        $(this).removeClass('sughover');
    }
});
$("#quality2").blur(function () {
    $("#qualitySuggest2").hide();
});


});
function finishAjax(id, response) {
$('#' + id).html(unescape(response));
$('#' + id).show();
} //finishAjax

ご協力いただきありがとうございます!

4

1 に答える 1

0

私のクリックイベントはぼかしイベントの後に呼び出されていたため、提案のドロップダウンは非表示になりました。クリックイベントをmousedownに変更することで、これを解決しました。その後、ぼかしの前にマウスダウンが呼び出されます。

于 2012-12-05T23:42:17.660 に答える