说我有以下HTML:
<div>
<span>span text</span> div text <span>some more text</span>
</div>
Run Code Online (Sandbox Code Playgroud)
我想这样做,以便当我单击span时将触发一些事件(例如,使文本变为粗体),这很容易:
$('span').click( ... )
Run Code Online (Sandbox Code Playgroud)
但是现在当我单击远离元素时,我希望触发另一个事件(例如,使文本变为正常粗细)。我需要以某种方式检测不在span元素内的单击。这与blur()事件非常相似,但是对于非INPUT元素。我不介意此点击是否仅在DIV元素内部而非页面的整个主体内检测到,顺便说一句。
我试图通过以下方法在非SPAN元素中触发事件:
$('div').click( ... ) // triggers in the span element
$('div').not('span').click( ... ) // still triggers in the span element
$('div').add('span').click( ... ) // triggers first from span, then div
Run Code Online (Sandbox Code Playgroud)
另一种解决方案是在click事件中读取事件的目标。这是以这种方式实现的示例:
$('div').click(function(e) {
if (e.target.nodeName != "span")
...
});
Run Code Online (Sandbox Code Playgroud)
我想知道是否还有更优雅的解决方案,例如blur()。
我需要能够使用鼠标单击位置绘制多边形.这是我目前的代码:
//the drawshape varible is called when a button is pressed to select use of this tool
if (DrawShape == 4)
{
Point[] pp = new Point[3];
pp[0] = new Point(e.Location.X, e.Location.Y);
pp[1] = new Point(e.Location.X, e.Location.Y);
pp[2] = new Point(e.Location.X, e.Location.Y);
Graphics G = this.CreateGraphics();
G.DrawPolygon(Pens.Black, pp);
}
Run Code Online (Sandbox Code Playgroud)
谢谢
当用户单击鼠标侧面的后退/前进按钮时,是否可以使用JavaScript进行检测?据我所知,这些被称为XButton,至少在.net中.这适用于本地安装的应用程序,因此我不需要跨浏览器支持,只需在IE中运行.
我在表单上有一个按钮,想要处理左右点击.
我正在处理MouseClick事件,但这只是在左键单击时引发的.
这是我的代码中的某个地方(我错过了一个设置)或预期的功能吗?
如果无法解决这个问题,那么处理MouseUp事件的最佳解决方法是什么?
我想使用MouseClick的原因是自动识别双击.
感谢您的任何反馈.
在WPF/C#中,MouseRightButtonDown和MouseLeftButtonDown上有事件,但中心鼠标按钮怎么样?
中心鼠标按钮是向下/向上,例如WPF中的事件被遗忘了吗?
如何检查中心按钮是否被单击或释放?
点击事件不响应鼠标右键单击.该事件适用于richTextBox.当我在表单上尝试相同的代码时,它工作正常.
可能是什么问题呢?
编辑:我使用winforms
现在的想法是(而不是运动.png图像)用标准HTML元素填充图层,就像制作一个漂亮的移动2D网页一样.
你可以猜到我的第一个问题.无论我尝试什么,我都无法使点击事件通过100x100%div层找到 一个可点击的(或其他?)元素,而不是.layer本身.
也许制作图层height:0px; position:absolute;而不是附加相对定位的元素?
但每次用户点击页面上的任何内容时,剩余时间必须再次重置为 30 秒(或者作为另一个选项,将使用clearTimeOut 和 setTimeOut。)同时,当用户没有点击页面上的任何内容时,他们通过删除 accessToken,将在 30 秒后自动注销。
所以为了解决这个问题,我的方法是这样的:
当用户访问此页面时,setTimeout() 将开始。
当用户单击页面上的某些内容时,clearTimeOut 将被激活,setTimeOut 也将再次被激活
当用户30秒内没有点击页面上的任何内容时,他们将通过删除本地存储中的accessToken自动注销
目前,通过删除 accessToken 可以让用户在 30 秒后注销!UseEffect 中的 setTimeOut 也有效。
唯一的问题是我不知道当用户在页面上单击事件时如何使clearTimeOut()和setTimeOut工作。
import styled from 'styled-components';
import React, {useRef, useEffect, useState} from 'react';
import ScreenContainer from '../../src/component/common/ScreenContainer';
import {useNavigate as useDomNavigate} from 'react-router-dom';
import isNil from 'lodash/isNil';
import userClient from '../../src/client/user/userClient';
const Device = () => {
const domNavigate = useDomNavigate();
const [storeId, setStoreId] = useState(() => JSON.parse(localStorage.getItem('storeId')));
const [currentDeposit, setCurrentDeposit] = …Run Code Online (Sandbox Code Playgroud) 当左键单击鼠标时,应该交换彼此水平相邻的颜色,当右键单击时,垂直相邻的颜色应该交换.单击任一按钮时都没有发生任何事情.
有问题的代码:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import sun.java2d.loops.DrawRect;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
public class Board extends JPanel implements MouseListener
{
//instance variables
private int width;
private int height;
private Block topLeft;
private Block topRight;
private Block botLeft;
private Block botRight;
public Board() //constructor
{
width = 200;
height = 200;
topLeft=new Block(0,0,width/2-10,height/2-10,Color.RED);
topRight=new Block(width/2,0,width/2-10,height/2-10,Color.GREEN);
botLeft=new Block(0,height/2,width/2-10,height/2-10,Color.BLUE);
botRight=new Block(width/2,height/2,width/2-10,height/2-10,Color.YELLOW);
setBackground(Color.WHITE);
setVisible(true);
//start trapping for mouse clicks
addMouseListener(this);
}
//initialization constructor
public Board(int w, int h) //constructor
{
width = …Run Code Online (Sandbox Code Playgroud) 我正在尝试为一组动态创建的标签创建一个click事件,如下所示:
private void AddLBL_Btn_Click(object sender, EventArgs e)
{
int ListCount = listBox1.Items.Count;
int lbl = 0;
foreach (var listBoxItem in listBox1.Items)
{
Label LB = new Label();
LB.Name = "Label" + listBoxItem.ToString();
LB.Location = new Point(257, (51 * lbl) + 25);
LB.Size = new Size(500, 13);
LB.Text = listBoxItem.ToString();
Controls.Add(LB);
lbl++;
}
LB.Click += new EventHandler(PB_Click);// error here
}
protected void LB_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.mysite/" + LB);//Navigate to site on label
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:"当前上下文中不存在名称'LB'"因为我在循环中创建了LB而且我不够聪明知道如何声明LB所以我可以在循环之外使用它.
另外,我想将标签名称(listBoxItem)传递给click事件,并将它放在WebBrowser调用中的位置.喜欢:webBrowser1.Navigate(" http://www.mysite/ "+ LB); //导航到标签上的网站
mouseclick-event ×10
c# ×5
jquery ×2
winforms ×2
awt ×1
button ×1
cleartimeout ×1
events ×1
java ×1
javascript ×1
layer ×1
logout ×1
mouse ×1
parallax ×1
polygon ×1
reactjs ×1
right-click ×1
settimeout ×1
swing ×1
wpf ×1