gpt4 book ai didi

javascript - 按键后如何删除背景图像?

转载 作者:太空宇宙 更新时间:2023-11-04 05:03:28 24 4
gpt4 key购买 nike

当用户在文本框中输入内容时,我会显示一个纺车图像,在 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" />

更新我更正了拼写错误,但它仍然不起作用。

最佳答案

你有一个错字:

$(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
});
});
});
});

关于javascript - 按键后如何删除背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11005419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com