javascript 单击链接时 jQuery 更改光标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5018753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 15:41:13  来源:igfitidea点击:

jQuery change cursor on click on link

javascriptjqueryjavascript-eventsaccessibility

提问by astropanic

How I can change the cursor css property of a link element, so when the user click on that link, the cursor switches from pointer to wait ?

如何更改链接元素的光标 css 属性,以便当用户单击该链接时,光标从指针切换到等待?

jQuery(document).ready(function(){
  jQuery('a.cursor_wait').click(function(){
    jQuery('body').css('cursor', 'wait');
  });
});

This works, but I must move with the mouse from the link to see the wait indicator, when I leave my cursor on the link, I still see the pointer.

这有效,但我必须用鼠标从链接上移动才能看到等待指示器,当我将光标留在链接上时,我仍然看到指针。

How can I make this work without moving my cursor ?

如何在不移动光标的情况下完成这项工作?

回答by Loktar

Example

例子

http://jsfiddle.net/loktar/3WLGt/4/

http://jsfiddle.net/loktar/3WLGt/4/

JS

JS

jQuery(document).ready(function(){
  jQuery('a.cursor_wait').click(function(){
    jQuery('body').css('cursor', 'wait');
      jQuery(this).css('cursor', 'wait');
  });
});

Changes the property of the current link to the wait cursor as well, because by default they are set to pointer.

也将当前链接的属性更改为等待光标,因为默认情况下它们被设置为指针。

回答by Saeed-rz

you want only wait cursor on your link? so why select body and change cursor?!

你只想在你的链接上等待光标?那么为什么选择正文并更改光标?!

$('a').css('cursor','wait');

回答by shahrokh nabavi

if I understand correctly , you want click on a link ( for example DELETE an item ) then change the courser to wait until your request will be done, turn it back to default...

如果我理解正确,您想单击一个链接(例如删除一个项目)然后更改课程以等待您的请求完成,将其恢复为默认值...

var c= confirm("Are you sure?");
if(c)
{ 
    document.body.style.cursor="wait";
    $.post("delete.php?id=212",function(data){
        alert('I\'ve done it...');
        document.body.style.cursor="default";
    });
} 

回答by Hilton

I got it to work changing the class of the a, and changing the jquery to $ as below:

我让它改变了 a 的类,并将 jquery 更改为 $,如下所示:

$(document).ready(function() {
    $('a').click(function() {
        $('body').css('cursor', 'wait');
        $(this).css('cursor', 'wait');
    });
});

However, this will work for all anchor tags a. You will need to specify the css class you want it to apply to.

但是,这将适用于所有锚标记 a。您需要指定要应用的 css 类。

回答by 3rgo

Try this (not tested) :

试试这个(未测试):

jQuery('body').trigger('hover');