0

当用户在文本框中键入时,我正在显示一个旋转的轮子图像,并且在完成 ajax 调用后,我想删除该图像。问题是图像不会消失。我确定代码已执行,因为我可以看到代码中所述的日志信息。我究竟做错了什么?

$(document).ready(function () {
    $("[NeedSpellCheck='true']").each(function () {
        $(this).keypress(function (e) {
            $(this).css("background-image", "url(images/loading.gif)");
            $(this).css("background-repeat", "no-repeat");
            $(this).css("background-position", "right");

            $(this).spellchecker(
            {
                url: "~/JQuerySpellCheckerHandler.ashx",
                lang: "en",
                engine: "google",
                suggestBoxPosition: "bottom"
            }).spellchecker("check", function (result) {
                $(this).css("background-image", "none"); // <-- corrected typo
                console.log("removed"); //<-- displayed in console
            });
        });
    });
});

<input type="text" NeedSpellCheck="true" />

更新 我纠正了错字,但它仍然不起作用。

4

2 回答 2

2

你有一个错字:

$(this).css("background-image", "none");

如果这不是问题,您可能需要在插件之外引用它:

$(document).ready(function () {
    $("[NeedSpellCheck='true']").each(function () {
        $(this).keypress(function (e) {
            var $this = $(this);  // you could use $this for the following as well
            $(this).css("background-image", "url(images/loading.gif)");
            $(this).css("background-repeat", "no-repeat");
            $(this).css("background-position", "right");

            $(this).spellchecker(
            {
                url: "~/JQuerySpellCheckerHandler.ashx",
                lang: "en",
                engine: "google",
                suggestBoxPosition: "bottom"
            }).spellchecker("check", function (result) {
                $this.css("background-image", "none");  // reference object
                console.log("removed"); //<-- displayed in console
            });
        });
    });
});
于 2012-06-12T21:53:59.883 回答
0

代替:

$(this).css("backbround-image", "none");

和:

$(this).css("background-image", "none");
于 2012-06-12T21:54:55.517 回答