当光标变为手时,鼠标单击事件 [英] Mouse Click event when cursor changes to hand

查看:99
本文介绍了当光标变为手时,鼠标单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想要一个简单的程序,它在后台运行并在光标形状变为手时执行单击。

I just want a simple program , which runs in the background and performs click when cursor shape changes to hand.

推荐答案

首先,所有类似的事件都是与ASP.NET无关,并且通过JavaScript调用并主要在客户端进行处理。即使你通过ASP.NET注册客户端脚本,它们仍然是JavaScript。



其次,没有这样的事件。在这里,您正在交换效果原因 https:// en .wikipedia.org / wiki / Causality [ ^ ] , https://en.wikipedia.org/wiki/Cause_and_effect [ ^ ])。



手形光标是效果而不是原因。由某些事件引起的光标更改,例如 mouseover mouseout 。另一个故事是:您可能没有处理这些事件的JavaScript代码,因为鼠标指针形状根据CSS样式而改变。但是我们在这里设置CSS。这些是您需要处理的事件。请参阅: http://www.quirksmode.org/js/events_mouse.html [ ^ ]。



此外,您不需要在后台运行的任何内容,也不需要执行单击的任何内容。只有用户才能执行点击。您可能需要调用某些函数,这些函数也会在某些单击时调用。不是很简单。所以,基本上,这就是你所做的:

First of all, all similar events are not related to ASP.NET and are invoked and primarily handled on the client side via JavaScript. Even if you register client-side scripts via ASP.NET, they are still JavaScript.

Secondly, there is no such event. Here, you are swapping the effect and the cause (https://en.wikipedia.org/wiki/Causality[^], https://en.wikipedia.org/wiki/Cause_and_effect[^]).

The hand cursor is the effect, not the cause. The cursor is changed caused by some event, such as mouseover and mouseout. Another story is: you may not have any JavaScript code handling these events, because the mouse pointer shape is changed according to CSS styles. But let's set CSS aside here. These are the events you need to handle. Please see: http://www.quirksmode.org/js/events_mouse.html[^].

Also, you don't need anything which "runs in the background", and nothing which "performs the click". Only the user performs the click. You probably need to call some functions which are also called on some click. Isn't it simple. So, basically, this is what you do:
var myElement = document.getElementById("someId")
var myFirstButton = //...
var mySecondButton = //...
myElement.onmouseover = function(eventInstance) { doSomething(); }
myElement.onmouseout  = function(eventInstance) { doSomethingElse(); }
//... and possibly, just for example:
myFirstButton.onclick = function(eventInstance) { doSomething(); }
// and/or
mySecondButton.onclick = function(eventInstance) { doSomethingElse(); }



请注意,您通常应在 body.onload 事件的处理程序中设置元素处理程序。



不幸的是,您的在后台运行表示您可能无法理解面向事件的UI编程,并且事情的工作方式并不像您想象的那样。



-SA


Note that you generally should setup element handlers in the handler of the body.onload event.

Unfortunately, your "run in the background" indicates that you possible don't understand the event-oriented UI programming and that things work not as you think.

—SA


这篇关于当光标变为手时,鼠标单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆