我有这样的事情:
$('#eventFire').dblclick(function(){
EventHandler.dblclickListener();
});
Run Code Online (Sandbox Code Playgroud)
我想让 EventHandler 监听双击事件,我想让 EventHandler 知道页面中的哪个元素触发了这个事件,我该怎么做?谢谢你。
简单的问题——有没有人知道一个可靠的跨浏览器函数来从 keydown 事件中输入字符?我可以从 quirksmode 网格中编写一个,但宁愿不为如此简单但如此非标准的东西重新发明轮子。
让我澄清一下:
仅使用event.keyCode或无法做到这一点event.which。整体逻辑是这样的:
{186 : ';', 187 : '=', 188 : ',', ....}String.fromCharCode(key)这不是一个简单的解决方案,这就是为什么我正在寻找一个预制的解决方案:)
我有以下html:
<div id="div1">
<div id="div2">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
document.addEventListener('mousedown', function(e){
console.log(e.target);
});
Run Code Online (Sandbox Code Playgroud)
如果鼠标在 div2 上点击,那么 e.target 就是 div2。在这种情况下,我希望目标是 div1。是否可以?
我有一个包含许多元素的页面,每个元素都有一个绑定到单击事件的回调。
页面比视口大,用户可以按标准方式滚动(使用鼠标滚轮、滚动条......)
现在我需要实现pan mode,为用户提供另一种滚动页面的方式:
用户点击,用鼠标向下拖动,页面滚动。
我实现了在 body 元素上轻松注册 mousedown、mousemove 和 mouseup。当用户拖动时,我使用window.scrollTo()滚动窗口
问题:当页面在鼠标指针下移动时,如果用户平移页面点击一个元素,那么 mousedown 和 mouseup 发生在同一个元素上,这也会在 mouseup 之后触发该元素上的click 事件。
这当然是不需要的。
click 事件在一个子元素上(鼠标向下移动在身体上)所以stopPropagation没有帮助。
问题:在 mouseup 回调结束时,当实际发生拖动时(我可以检查这个比较初始和最终鼠标坐标),我可以阻止点击事件触发吗?
如何使用javascript更改onclick?
https://jsfiddle.net/749rt0m7/1/
我试图使用这段代码,但不行.我能怎么做 ?
<span onclick="test_fn('aaa,bbb')" id="xx">edit</span>
<script>
document.getElementById('xx').onclick = "test_fn(111,222)";
</script>
Run Code Online (Sandbox Code Playgroud) 我正在寻找迭代对象getEventListeners(obj)返回的方法.这样,我就不需要特定的代码来迭代事件监听器类型,或者检查它们是否存在于checked元素上.我的目标是从元素中删除一些事件侦听器.例如,删除所有鼠标相关的,并保留其他.
谢谢
如何根据超时ID找到超时延迟(如果超时ID不可能,则可能是其他内容,如超时对象等)
timeoutID = window.setTimeout(slowAlert, 2000);
getOriginalTimeoutValue(timeoutId);
function getOriginalTimeoutValue(timeoutId) {
// find original timeout delay (i.e. 2000)
}
Run Code Online (Sandbox Code Playgroud) 我已经在vue路由器的路由所使用的组件的已创建钩子上注册了“ beforeunload”事件。
我想调用此事件处理程序,以删除浏览器选项卡关闭或浏览器选项卡刷新或浏览器关闭上的用户。
在ComponentA上
created (){
window.addEventListener('beforeunload', () => {
this.removeUser()
return null
})
}
Run Code Online (Sandbox Code Playgroud)
嘲笑ComponentB
created (){
window.addEventListener('beforeunload', () => {
this.removeUser()
return null
})
}
Run Code Online (Sandbox Code Playgroud)
还有我的router.js
{
path: '/staff/call/:session_key',
name: 'Staff Call',
component: ComponentA,
meta: {auth: true}
},
{
path: '/consumer/call/:session_key',
name: 'Consumer Call',
component: ComponentB
},
Run Code Online (Sandbox Code Playgroud)
在这里,“ beforeunload”事件处理程序是随机触发的。那有时是触发它,有时却没有触发。我认为在触发时会发现任何模式,而在没有触发时会发现。
我在这里想念什么?
我正在尝试制作一个图像,当你点击它时它会带你到一个显示页面,但是在那个图像中我需要有一些按钮来制作其他东西:
<div
className="prop-detail"
key={dwelling._id}
onClick={() => this.props.history.push(`/propiedades/${dwelling._id}`)}
>
<img
src={dwelling.images[0] !== undefined
? dwelling.images[0].secure_url
: 'https://res.cloudinary.com/sioc/image/upload/v1525712940/epnvioppkpvwye1qs66z.jpg'}
alt=""
/>
<div className="prop-text">
{dwelling.price
? <span>{dwelling.price} {dwelling.currency}</span>
: <span>Consulte</span>}
<small> {dwelling.spaces.rooms}h - {dwelling.spaces.bathRoom}b</small>
<p>Calle {dwelling.address.streetName} {dwelling.address.streetNumber}, {dwelling.address.city}, {dwelling.address.state}</p>
</div>
<div className="prop-detail-btns">
<Button
className="goto"
onClick={() => this.handleRefs(dwelling.address, index)}>
<FontAwesome name="map-marker" size="25"/>
</Button>{' '}
<Button className="like">
<FontAwesome name="heart" size="25"/>
</Button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的问题是当我点击按钮时它也需要div onClick
处理onChange事件时,这个工作
<input type="file" onChange={this.onChange}
Run Code Online (Sandbox Code Playgroud)
不是这一个,即时执行该功能
<input type="file" onChange={this.onChange()}
Run Code Online (Sandbox Code Playgroud)
不是这个,不执行
<input type="file" onChange={() => this.onChange}
Run Code Online (Sandbox Code Playgroud)
但是这个确实如此
<input type="file" onChange={() => this.onChange()}
Run Code Online (Sandbox Code Playgroud)
但是,当第一个自动发出事件对象时,第二个需要明确它
<input type="file" onChange={(e) => this.onChange(e)}
onChange(e) {
console.log(e.target.files[0])
}
Run Code Online (Sandbox Code Playgroud)
这是为什么?我们什么时候应该使用一个或另一个?
forms javascript-events ecmascript-6 reactjs arrow-functions
javascript ×6
jquery ×2
onclick ×2
reactjs ×2
ecmascript-6 ×1
forms ×1
html ×1
mouseup ×1
pan ×1
settimeout ×1
vue-router ×1
vue.js ×1
vuejs2 ×1