jQuery更改光标点击链接

时间:2022-11-21 15:41:25

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 ?

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

5 个解决方案

#1


1  

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.

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

#2


1  

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

你只想在你的链接上等待光标吗?为什么选择身体并更换光标?!

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

#3


0  

Try this (not tested) :

试试这个(未经测试):

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

#4


0  

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...

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

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";
    });
} 

#5


0  

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类。

#1


1  

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.

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

#2


1  

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

你只想在你的链接上等待光标吗?为什么选择身体并更换光标?!

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

#3


0  

Try this (not tested) :

试试这个(未经测试):

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

#4


0  

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...

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

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";
    });
} 

#5


0  

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类。